public bool Update(int userId, int id, ref object dto, out Notification notification) { DTO.OPSequenceDto dtoItem = ((Newtonsoft.Json.Linq.JObject)dto).ToObject <DTO.OPSequenceDto>(); notification = new Notification() { Type = NotificationType.Success }; try { using (OPSequenceEntities context = CreateContext()) { OPSequence dbItem; if (id > 0) { if (this.HasBOM(id)) { throw new Exception("There are some BOM which are using OP Sequence, so you can not change !!!"); } dbItem = context.OPSequence.FirstOrDefault(s => s.OPSequenceID == id); if (dbItem == null) { notification = new Notification() { Type = NotificationType.Error, Message = "Can not find data" }; return(false); } } else { dbItem = new OPSequence(); context.OPSequence.Add(dbItem); } converter.DTO2DB_Update(dtoItem, ref dbItem); dbItem.CompanyID = fwFactory.GetCompanyID(userId); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; context.OPSequenceDetail.Local.Where(o => o.OPSequence == null).ToList().ForEach(o => context.OPSequenceDetail.Remove(o)); context.SaveChanges(); dto = Get(dbItem.OPSequenceID, out notification).Data; } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
private bool HasBOM(int opSequenceID) { try { using (OPSequenceEntities context = CreateContext()) { return(context.OPSequence_function_HasBOM(opSequenceID).FirstOrDefault().Value > 0); } } catch { } return(false); }
public DTO.EditData Get(int id, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; DTO.EditData data = new EditData() { Data = new OPSequenceDto() }; try { if (id > 0) { using (OPSequenceEntities context = CreateContext()) { OPSequence_OPSequence_View dbItem = context.OPSequence_OPSequence_View.FirstOrDefault(s => s.OPSequenceID == id); if (dbItem == null) { notification = new Notification() { Type = NotificationType.Error, Message = "Can not find data." }; return(data); } data.Data = converter.DB2DTO_Get(dbItem); } } else { data.Data.OPSequenceDetails = new List <OPSequenceDetailDto>(); } Module.Support.DAL.DataFactory support_factory = new Support.DAL.DataFactory(); data.WorkCenters = support_factory.GetWorkCenter(); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(data); } return(data); }
public bool Delete(int id, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; try { using (OPSequenceEntities context = CreateContext()) { OPSequence dbItem = context.OPSequence.FirstOrDefault(s => s.OPSequenceID == id); if (dbItem == null) { notification = new Notification() { Type = NotificationType.Error, Message = "Can not find data." }; return(false); } context.OPSequence.Remove(dbItem); context.SaveChanges(); } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }