public bool ImportExcelData(int userId, ref object dtoItem, out Library.DTO.Notification notification) { List <DTO.ImportFactoryBreakdown> dtoFactoryBreakdowns = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.ImportFactoryBreakdown> >(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FactoryBreakdownMngEntities context = CreateContext()) { foreach (DTO.ImportFactoryBreakdown dtoFactoryBreakdown in dtoFactoryBreakdowns.ToList()) { FactoryBreakdown dbFactoryBreakdown; dbFactoryBreakdown = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == dtoFactoryBreakdown.FactoryBreakdownID); converter.DTO2DB_ImportFactoryBreakdown(dtoFactoryBreakdown, ref dbFactoryBreakdown, userId); } context.SaveChanges(); return(true); } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public override bool Approve(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FactoryBreakdownMngEntities context = CreateContext()) { FactoryBreakdown dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id); if (dbItem == null) { notification.Message = "Factory breakdown not found!"; return(false); } else { // check data access permission if (dbItem.SampleProductID.HasValue) { if (CheckSamplePermission(userId, dbItem.SampleProductID.Value) <= 0) { throw new Exception("Data access not authorized!"); } } //else //{ // throw new Exception("Invalid sample product data! (id null)"); //} // validate data if (!dbItem.IndicatedPrice.HasValue || dbItem.IndicatedPrice <= 0) { throw new Exception("Invalid indicated price!"); } FactoryBreakdownDetail dbDetail = dbItem.FactoryBreakdownDetail.FirstOrDefault(o => o.FactoryBreakdownCategoryID == 11); // load ability if (dbDetail == null || !dbDetail.Quantity.HasValue || dbDetail.Quantity <= 0) { throw new Exception("Invalid load ability!"); } dbItem.IsConfirmed = true; dbItem.ConfirmedBy = userId; dbItem.ConfirmedDate = DateTime.Now; context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public override bool Reset(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FactoryBreakdownMngEntities context = CreateContext()) { FactoryBreakdown dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id); if (dbItem == null) { notification.Message = "Factory breakdown not found!"; return(false); } else { // check data access permission if (dbItem.SampleProductID.HasValue) { if (CheckSamplePermission(userId, dbItem.SampleProductID.Value) <= 0) { throw new Exception("Data access not authorized!"); } } else { throw new Exception("Invalid sample product data! (id null)"); } dbItem.IsConfirmed = false; dbItem.ConfirmedBy = null; dbItem.ConfirmedDate = null; context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.FactoryBreakdownDTO dtoBreakdown = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryBreakdownDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { // check data access permission if (dtoBreakdown.SampleProductID.HasValue) { if (CheckSamplePermission(userId, dtoBreakdown.SampleProductID.Value) <= 0) { throw new Exception("Data access not authorized!"); } } //else //{ // throw new Exception("Invalid sample product data! (id null)"); //} using (FactoryBreakdownMngEntities context = CreateContext()) { FactoryBreakdown dbItem = null; if (id == 0) { dbItem = new FactoryBreakdown(); context.FactoryBreakdown.Add(dbItem); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; } else { dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id); } if (dbItem == null) { notification.Message = "Factory breakdown not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; converter.DTO2DB_FactoryBreakdown(dtoBreakdown, ref dbItem, userId); context.FactoryBreakdownDetail.Local.Where(o => o.FactoryBreakdown == null).ToList().ForEach(o => context.FactoryBreakdownDetail.Remove(o)); context.FactoryBreakdownModel.Local.Where(o => o.FactoryBreakdown == null).ToList().ForEach(o => context.FactoryBreakdownModel.Remove(o)); context.SaveChanges(); dtoItem = GetData(userId, dbItem.FactoryBreakdownID, dbItem.SampleProductID, dbItem.ModelID, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }