public bool DeleteFactoryFinishedProductPrice(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; try { using (FactoryFinishedProductEntities context = CreateContext()) { var dbItem = context.FactoryFinishedProductPrice.Where(o => o.FactoryFinishedProductPriceID == id).FirstOrDefault(); context.FactoryFinishedProductPrice.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 CreateFactoryFinishedProductPrice(int factoryFinishedProductID, object dtoObjectItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success, Message = "Update success" }; DTO.FactoryFinishedProductPriceDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoObjectItem).ToObject <DTO.FactoryFinishedProductPriceDTO>(); try { if (!dtoItem.FactoryTeamID.HasValue) { throw new Exception("You have to select team"); } if (!dtoItem.FactoryStepID.HasValue) { throw new Exception("You have to select step"); } using (FactoryFinishedProductEntities context = CreateContext()) { FactoryFinishedProductPrice dbItem; if (dtoItem.FactoryFinishedProductPriceID > 0) { dbItem = context.FactoryFinishedProductPrice.Where(o => o.FactoryFinishedProductPriceID == dtoItem.FactoryFinishedProductPriceID).FirstOrDefault(); } else { dbItem = new FactoryFinishedProductPrice(); dbItem.FactoryFinishedProductID = factoryFinishedProductID; context.FactoryFinishedProductPrice.Add(dbItem); } if (dbItem != null) { dbItem.FactoryTeamID = dtoItem.FactoryTeamID; dbItem.FactoryStepID = dtoItem.FactoryStepID; dbItem.Price = dtoItem.Price; dbItem.HalfRoundPrice = dtoItem.HalfRoundPrice; dbItem.DoubleRoundPrice = dtoItem.DoubleRoundPrice; } else { throw new Exception("Could not find data. You have to save data before update component price"); } context.SaveChanges(); return(dbItem.FactoryFinishedProductPriceID); } } 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.FactoryFinishedProductDTO dtoFactoryFinishedProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryFinishedProductDTO>(); try { using (FactoryFinishedProductEntities context = CreateContext()) { FactoryFinishedProduct dbItem = null; if (id > 0) { dbItem = context.FactoryFinishedProduct.Where(o => o.FactoryFinishedProductID == id).FirstOrDefault(); } else { dbItem = new FactoryFinishedProduct(); context.FactoryFinishedProduct.Add(dbItem); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { //convert dto to db converter.DTO2DB_FactoryFinishedProduct(dtoFactoryFinishedProduct, ref dbItem); context.SaveChanges(); //get return data dtoItem = GetData(dbItem.FactoryFinishedProductID, 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); } }