private bool unitValidation(Unit unit, long[] checkedRecords)
{
bool check = true;
UnitManager unitManager = new UnitManager();
List<Unit> unitList = unitManager.Repo.Get().ToList(); ;
if (unit.Name == null || unit.Name == "")
{
Session["nameMsg"] = "invalid Name";
check = false;
}
else
{
bool nameExist = !(unitList.Where(p => p.Name.ToLower().Equals(unit.Name.ToLower())).Count().Equals(0));
if (nameExist)
{
Unit tempUnit = unitList.Where(p => p.Name.ToLower().Equals(unit.Name.ToLower())).ToList().First();
if (unit.Id != tempUnit.Id)
{
Session["nameMsg"] = "Name already exist";
check = false;
}
else
{
Session["nameMsg"] = null;
}
}
else
{
Session["nameMsg"] = null;
}
}
if (unit.Abbreviation == null || unit.Abbreviation == "")
{
Session["abbrMsg"] = "invalid Abbreviation";
check = false;
}
else
{
bool abbreviationExist = !(unitList.Where(p => p.Abbreviation.ToLower().Equals(unit.Abbreviation.ToLower())).Count().Equals(0));
if (abbreviationExist)
{
Unit tempUnit = unitList.Where(p => p.Abbreviation.ToLower().Equals(unit.Abbreviation.ToLower())).ToList().First();
if (unit.Id != tempUnit.Id)
{
Session["abbrMsg"] = "Abbreviation already exist";
check = false;
}
else
{
Session["abbrMsg"] = null;
}
}
else
{
Session["abbrMsg"] = null;
}
}
if (checkedRecords != null)
{
Session["dataTypeMsg"] = null;
}
else
{
Session["dataTypeMsg"] = "Choose at least one Data Type.";
check = false;
}
if (!String.IsNullOrEmpty(unit.Dimension.Name) && unit.Dimension.Name != "Select or Enter")
{
Session["dimensionMsg"] = null;
}
else
{
Session["dimensionMsg"] = "Select or create an Dimension.";
check = false;
}
return check;
}