public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (CushionMngEntities context = CreateContext()) { Cushion dbItem = context.Cushion.FirstOrDefault(o => o.CushionID == id); if (dbItem == null) { notification.Message = "Cushion not found!"; return(false); } else { context.Cushion.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.CushionMng.Cushion dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (CushionMngEntities context = CreateContext()) { Cushion dbItem = null; if (id == 0) { dbItem = new Cushion(); context.Cushion.Add(dbItem); } else { dbItem = context.Cushion.FirstOrDefault(o => o.CushionID == id); } if (dbItem == null) { notification.Message = "Cushion not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoItem, ref dbItem); context.SaveChanges(); // processing image if (dtoItem.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); } context.SaveChanges(); dtoItem = GetData(dbItem.CushionID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD(DTO.CushionMng.Cushion dtoItem, ref Cushion dbItem) { AutoMapper.Mapper.Map <DTO.CushionMng.Cushion, Cushion>(dtoItem, dbItem); dbItem.UpdatedDate = DateTime.Now; }