public bool DeleteMaterialGroupTeam(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; try { using (FactoryTeamEntities context = CreateContext()) { var dbItem = context.FactoryMaterialGroupTeam.Where(o => o.FactoryMaterialGroupTeamID == id).FirstOrDefault(); context.FactoryMaterialGroupTeam.Remove(dbItem); context.SaveChanges(); } return(true); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(false); } }
public int CreateFactoryTeamStep(int factoryTeamID, object dtoObjectItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success, Message = "Update success" }; DTO.FactoryTeamStepDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoObjectItem).ToObject <DTO.FactoryTeamStepDTO>(); try { if (!dtoItem.FactoryStepID.HasValue) { throw new Exception("You have to select step"); } if (!dtoItem.StepIndex.HasValue) { throw new Exception("You have to fill-in index"); } using (FactoryTeamEntities context = CreateContext()) { FactoryTeamStep dbItem; if (dtoItem.FactoryTeamStepID > 0) { dbItem = context.FactoryTeamStep.Where(o => o.FactoryTeamStepID == dtoItem.FactoryTeamStepID).FirstOrDefault(); } else { dbItem = new FactoryTeamStep(); dbItem.FactoryTeamID = factoryTeamID; context.FactoryTeamStep.Add(dbItem); } if (dbItem != null) { dbItem.FactoryStepID = dtoItem.FactoryStepID; dbItem.StepIndex = dtoItem.StepIndex; } else { throw new Exception("Could not find data. You have to save data before update team step"); } context.SaveChanges(); return(dbItem.FactoryTeamStepID); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(-1); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.FactoryTeamDTO dtoFactoryTeam = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryTeamDTO>(); try { using (FactoryTeamEntities context = CreateContext()) { FactoryTeam dbItem = null; if (id > 0) { dbItem = context.FactoryTeam.Where(o => o.FactoryTeamID == id).FirstOrDefault(); } else { dbItem = new FactoryTeam(); context.FactoryTeam.Add(dbItem); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { //convert dto to db converter.DTO2DB_FactoryTeam(dtoFactoryTeam, ref dbItem); context.SaveChanges(); //get return data dtoItem = GetData(dbItem.FactoryTeamID, out notification); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(false); } }