public static Models.ValidationResult AddBootEntry(Models.BootEntry bootEntry) { using (var uow = new DAL.UnitOfWork()) { var validationResult = ValidateEntry(bootEntry, true); if (validationResult.IsValid) { uow.BootEntryRepository.Insert(bootEntry); validationResult.IsValid = uow.Save(); } return(validationResult); } }
public static Models.ValidationResult UpdateBootEntry(Models.BootEntry bootEntry) { using (var uow = new DAL.UnitOfWork()) { var validationResult = ValidateEntry(bootEntry, false); if (validationResult.IsValid) { uow.BootEntryRepository.Update(bootEntry, bootEntry.Id); validationResult.IsValid = uow.Save(); } return(validationResult); } }
public static Models.ValidationResult ValidateEntry(Models.BootEntry bootEntry, bool isNewEntry) { var validationResult = new Models.ValidationResult(); if (string.IsNullOrEmpty(bootEntry.Name)) { validationResult.IsValid = false; validationResult.Message = "Boot Entry Name Is Not Valid"; return(validationResult); } if (isNewEntry) { using (var uow = new DAL.UnitOfWork()) { if (uow.BootEntryRepository.Exists(h => h.Name == bootEntry.Name)) { validationResult.IsValid = false; validationResult.Message = "This Boot Entry Already Exists"; return(validationResult); } } } else { using (var uow = new DAL.UnitOfWork()) { var originalTemplate = uow.BootEntryRepository.GetById(bootEntry.Id); if (originalTemplate.Name != bootEntry.Name) { if (uow.BootEntryRepository.Exists(h => h.Name == bootEntry.Name)) { validationResult.IsValid = false; validationResult.Message = "This Boot Template Already Exists"; return(validationResult); } } } } return(validationResult); }