public ActionResult DefineStructure(StructureDetails viewModel) { IStructuredetailRepository objstruct = new StructuredetailRepository(); var validate = objstruct.Getcondition(viewModel.CompanyCode, viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var validate1 = objstruct.Getcondition1(viewModel.CompanyCode, viewModel.CityCode).FirstOrDefault(); var validate3 = objstruct.Getcondition2(viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var check = objstruct.Getcondition3(viewModel.CityCode).FirstOrDefault(); var check1 = objstruct.Getcondition4(viewModel.CityName).FirstOrDefault(); var check2 = objstruct.Getcondition5(viewModel.CompanyCode).FirstOrDefault(); if (validate == null && validate3 != null || validate1 == null && check1 == null || !objstruct.GetAll().Any()) { if (ModelState.IsValid) { objstruct.Add(viewModel.CompanyCode, viewModel.CityCode, viewModel.CompanyName, viewModel.CityName); objstruct.Save(); RedirectToAction("StructureList", "Home"); TempData["SuccessMessage"] = "Structure Created"; } else { TempData["ErrorMessage"] = "Unable to Add"; } } else if (validate1 != null) { TempData["ErrorMessage"] = ("CompanyCode " + viewModel.CompanyCode + " with CityCode " + viewModel.CityCode + "Already Exists"); } else if (validate3 != null) { TempData["ErrorMessage"] = ("City Code " + viewModel.CityCode + " with City " + viewModel.CityName + " already Exists"); } else if (validate != null && validate1 != null && validate3 != null) { TempData["ErrorMessage"] = ("Company Code " + viewModel.CompanyCode + " with City Code " + viewModel.CityCode + "and" + viewModel.CityName + " Already Exists"); } else { TempData["ErrorMessage"] = ("City with Name " + viewModel.CityName + " already Exists in Company Code " + viewModel.CompanyCode + ""); } return(View(viewModel)); }
public ActionResult DefineSlPurchOrg(tblOrganizationStructure obj) { IStructuredetailRepository objstruct = new StructuredetailRepository(); var validate = objstruct.Getcondition1(obj.CompanyCode, Convert.ToInt32(obj.CityCode)).FirstOrDefault(); var validate1 = objstruct.Getvalidation(obj.CompanyCode, Convert.ToInt32(obj.CityCode), obj.StorageLocation, obj.PurchaseOrganization).FirstOrDefault(); var validate2 = context.tblOrganizationStructures .Where(a => a.CompanyCode == obj.CompanyCode) .Where(b => b.CityCode == obj.CityCode).FirstOrDefault(); var validate3 = context.tblOrganizationStructures .Where(c => c.StorageLocation == obj.StorageLocation) .Where(d => d.PurchaseOrganization == obj.PurchaseOrganization).FirstOrDefault(); if (validate == null) { TempData["ErrorMessage"] = ("CompanyCode " + obj.CompanyCode + " with CityCode " + obj.CityCode + " Does not Exists"); } else if (validate2 != null && validate3 != null) { TempData["ErrorMessage"] = (" Storage Location " + obj.StorageLocation + " with Purchase Organization " + obj.PurchaseOrganization + "Already Exists for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + " "); } else if (validate != null && validate1 == null && validate3 == null && validate2 != null) { if (ModelState.IsValid) { List <object> lst = new List <object>(); lst.Add(obj.CompanyCode); lst.Add(obj.CityCode); lst.Add(obj.StorageLocation); lst.Add(obj.PurchaseOrganization); object[] item = lst.ToArray(); int output1 = context.Database.ExecuteSqlCommand("insert into tblOrganizationStructure(CompanyCode,CityCode,StorageLocation,PurchaseOrganization) values(@p0,@p1,@p2,@p3)", item); if (output1 > 0) { TempData["SuccessMessage"] = ("Storage Location " + obj.StorageLocation + " and Purchase Org " + obj.PurchaseOrganization + " Defined for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + ""); } } else { TempData["ErrorMessage"] = "Unable to Add"; } } else if (validate2 == null && validate3 != null || validate2 == null && validate3 == null) { if (ModelState.IsValid) { List <object> lst = new List <object>(); lst.Add(obj.CompanyCode); lst.Add(obj.CityCode); lst.Add(obj.StorageLocation); lst.Add(obj.PurchaseOrganization); object[] item = lst.ToArray(); int output1 = context.Database.ExecuteSqlCommand("insert into tblOrganizationStructure(CompanyCode,CityCode,StorageLocation,PurchaseOrganization) values(@p0,@p1,@p2,@p3)", item); if (output1 > 0) { TempData["SuccessMessage"] = ("Storage Location " + obj.StorageLocation + " and Purchase Org " + obj.PurchaseOrganization + " Defined for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + ""); } } else { TempData["ErrorMessage"] = "Unable to Add"; } } else { TempData["ErrorMessage"] = (" Storage Location " + obj.StorageLocation + " with Purchase Organization " + obj.PurchaseOrganization + "Already Exists for Company Code " + obj.CompanyCode + " and City Code " + obj.CityCode + " "); } return(View(obj)); }