public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FrameMaterialColorMngEntities context = CreateContext()) { FrameMaterialColor dbItem = context.FrameMaterialColor.FirstOrDefault(o => o.FrameMaterialColorID == id); if (dbItem == null) { notification.Message = "Frame material color not found!"; return(false); } else { context.FrameMaterialColor.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD(DTO.FrameMaterialColorMng.FrameMaterialColor dtoItem, ref FrameMaterialColor dbItem) { AutoMapper.Mapper.Map <DTO.FrameMaterialColorMng.FrameMaterialColor, FrameMaterialColor>(dtoItem, dbItem); }
public override bool UpdateData(int id, ref DTO.FrameMaterialColorMng.FrameMaterialColor dtoItem, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; int number; string indexName; try { using (var context = CreateContext()) { FrameMaterialColor frameMaterialColor = null; if (id == 0) { frameMaterialColor = new FrameMaterialColor(); context.FrameMaterialColor.Add(frameMaterialColor); } else { frameMaterialColor = context.FrameMaterialColor.FirstOrDefault(o => o.FrameMaterialColorID == id); } if (frameMaterialColor == null) { notification.Message = "Frame Material Color not found!"; return(false); } else { converter.DTO2BD(dtoItem, ref frameMaterialColor); if (id <= 0) { // Generate code. using (var trans = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM FrameMaterialColor WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.FrameMaterialColorMng_function_GenerateCode().FirstOrDefault(); if (!"**".Equals(newCode)) { frameMaterialColor.FrameMaterialColorUD = newCode; context.SaveChanges(); } else { notification.Type = NotificationType.Error; notification.Message = "Auto generated code exceed maximum option: [ZZ]"; } } catch (Exception ex) { trans.Rollback(); throw ex; } finally { trans.Commit(); } } } else { context.SaveChanges(); } dtoItem = GetData(frameMaterialColor.FrameMaterialColorID, out notification).Data; return(true); } } } catch (DataException exData) { notification.Type = NotificationType.Error; ErrorHelper.DataExceptionParser(exData, out number, out indexName); if (number == 2601 && !string.IsNullOrEmpty(indexName)) { if ("FrameMaterialColorUDUnique".Equals(indexName)) { notification.Message = "The Frame Material Color Code is already exists."; } } else { notification.Message = exData.Message; } return(false); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } //notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; //try //{ // using (FrameMaterialColorMngEntities context = CreateContext()) // { // FrameMaterialColor dbItem = null; // if (id == 0) // { // dbItem = new FrameMaterialColor(); // context.FrameMaterialColor.Add(dbItem); // } // else // { // dbItem = context.FrameMaterialColor.FirstOrDefault(o => o.FrameMaterialColorID == id); // } // if (dbItem == null) // { // notification.Message = "Frame material color not found!"; // return false; // } // else // { // converter.DTO2BD(dtoItem, ref dbItem); // context.SaveChanges(); // dtoItem = GetData(dbItem.FrameMaterialColorID, out notification).Data; // return true; // } // } //} //catch (Exception ex) //{ // notification.Type = Library.DTO.NotificationType.Error; // notification.Message = ex.Message; // return false; //} }