public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ClientCityMngEntities context = CreateContext()) { ClientCity dbItem = context.ClientCities.FirstOrDefault(o => o.ClientCityID == id); if (dbItem == null) { notification.Message = "ClientCity not found!"; return(false); } else { context.ClientCities.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.ClientCityMng.ClientCity dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (ClientCityMngEntities context = CreateContext()) { ClientCity dbItem = null; if (id == 0) { dbItem = new ClientCity(); context.ClientCities.Add(dbItem); } else { dbItem = context.ClientCities.FirstOrDefault(o => o.ClientCityID == id); } if (dbItem == null) { notification.Message = "ClientCity not found!"; return(false); } else { converter.DTO2BD_ClientCity(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.ClientCityID, 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 == "ClientCityUDUnique") { notification.Message = "The ClientCity Code is already exists"; } } else { notification.Message = dEx.Message; } return(false); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }