public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SystemSettingMngEntities context = CreateContext()) { SystemSetting dbItem = context.SystemSettings.FirstOrDefault(o => o.SystemSettingID == id); if (dbItem == null) { notification.Message = "SystemSetting not found!"; return(false); } else { context.SystemSettings.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int id, ref DTO.SystemSettingMng.SystemSetting dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (SystemSettingMngEntities context = CreateContext()) { SystemSetting dbItem = null; if (id == 0) { dbItem = new SystemSetting(); context.SystemSettings.Add(dbItem); } else { dbItem = context.SystemSettings.FirstOrDefault(o => o.SystemSettingID == id); } if (dbItem == null) { notification.Message = "System Setting not found!"; return(false); } else { converter.DTO2BD_SystemSetting(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.SystemSettingID, out notification).Data; return(true); } } } catch (System.Data.DataException dEx) { notification.Type = Library.DTO.NotificationType.Error; Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName); if (number == 2601 && !string.IsNullOrEmpty(indexName)) { if (indexName == "SettingKeyUnique") { notification.Message = "Setting Key already exists!"; } } else { notification.Message = dEx.Message; } return(false); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }