public ActionResult QuarriesGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Quarries item) { if (ModelState.IsValid) { try { item.LastEditedBy = User.Identity.GetUserId(); item.EntryBy = User.Identity.GetUserId(); unitOfWork.QuarriesRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; ViewData["Model"] = item; } var model = unitOfWork.QuarriesRepo.Get(); return(PartialView("_QuarriesGridViewPartial", model)); }
public string ImportQuarries(bool?validate) { string errors = ""; int row = 1; foreach (DataRow i in DataTable.Rows) { var quarryName = i[0]?.ToString(); if (validate == true && unitOfWork.QuarriesRepo.Fetch(m => m.QuarryName == quarryName).Any()) { errors = quarryName + $" is already exist at row {row}"; break; } var quarry = new Models.Quarries() { QuarryName = i[0]?.ToString(), JurisdictionName = i[1]?.ToString(), EntryBy = UserId, LastEditedBy = UserId }; var barangayName = i[2]?.ToString(); List <Barangays> barangays = new List <Barangays>(); foreach (var b in barangayName.Split(',')) { barangays.Add(unitOfWork.BarangaysRepo.Find(m => m.Barangay == b) ?? new Barangays() { Barangay = b }); } quarry.Barangays = barangays; unitOfWork.QuarriesRepo.Insert(quarry); } unitOfWork.Save(); return(errors); }