public bool UpdateProductStatus2(int userId, int id, int statusId, string file, out Library.DTO.Notification notification) { // FINISH STATUS notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SampleItemMngEntities context = CreateContext()) { SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id); if (dbItem == null) { notification.Message = "Sample Product not found!"; return(false); } else { dbItem.SampleProductStatusID = statusId; dbItem.StatusUpdatedBy = userId; dbItem.StatusUpdatedDate = DateTime.Now; // update file if (!string.IsNullOrEmpty(file)) { dbItem.FinishedImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", file, dbItem.FinishedImage); } // add product item int totalExistingItem = dbItem.SampleProductItem.Count(); for (int index = 1; index <= dbItem.Quantity.Value - totalExistingItem; index++) { SampleProductItem dbProductItem = new SampleProductItem(); dbProductItem.SampleProductItemUD = dbItem.SampleProductUD + "-" + index.ToString("D2"); dbProductItem.CreatedDate = DateTime.Now; dbItem.SampleProductItem.Add(dbProductItem); } //// notification //SendNotification(context); context.SaveChanges(); // add item to quotation if needed context.FW_Quotation_function_AddSampleItem(null, id); // table lockx and also check if item is available on sql server side return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public void DTO2DB_SampleProduct(DTO.SampleProductDTO dtoItem, ref SampleProduct dbItem) { Mapper.Map <DTO.SampleProductDTO, SampleProduct>(dtoItem, dbItem); //Covert String to Dateime dbItem.StatusUpdatedDate = dtoItem.StatusUpdatedDate.ConvertStringToDateTime(); dbItem.FactoryDeadline = dtoItem.FactoryDeadline.ConvertStringToDateTime(); dbItem.ItemInfoUpdatedDate = dtoItem.ItemInfoUpdatedDate.ConvertStringToDateTime(); dbItem.ETADestination = dtoItem.ETADestination.ConvertStringToDateTime(); if (dtoItem.FactoryBreakdownDTO != null) { FactoryBreakdown dbFactoryBreakdown = dbItem.FactoryBreakdown.FirstOrDefault(); if (dbFactoryBreakdown != null) { Mapper.Map <DTO.FactoryBreakdownDTO, FactoryBreakdown>(dtoItem.FactoryBreakdownDTO, dbFactoryBreakdown); if (dtoItem.FactoryBreakdownDTO.FactoryBreakdownDetailDTOs != null) { foreach (var item in dtoItem.FactoryBreakdownDTO.FactoryBreakdownDetailDTOs) { FactoryBreakdownDetail dbFactoryBreakdownDetail = dbFactoryBreakdown.FactoryBreakdownDetail.FirstOrDefault(o => o.FactoryBreakdownDetailID == item.FactoryBreakdownDetailID); Mapper.Map <DTO.FactoryBreakdownDetailDTO, FactoryBreakdownDetail>(item, dbFactoryBreakdownDetail); } } } } }
public bool UpdateProductStatus(int userId, int id, int statusId, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SampleItemMngEntities context = CreateContext()) { SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id); if (dbItem == null) { notification.Message = "Sample Product not found!"; return(false); } else { dbItem.SampleProductStatusID = statusId; dbItem.StatusUpdatedBy = userId; dbItem.StatusUpdatedDate = DateTime.Now; // delete finished image if status is: 1,2,3,10 ~ CREATE,CONFIRMED,REVISED,REJECTED int[] statuses = { 1, 2, 3, 10 }; if (statuses.Contains(statusId)) { if (!string.IsNullOrEmpty(dbItem.FinishedImage)) { fwFactory.RemoveImageFile(dbItem.FinishedImage); dbItem.FinishedImage = string.Empty; } } // notification //SendNotification(context); context.SaveChanges(); // add item to quotation if needed context.FW_Quotation_function_AddSampleItem(null, id); // table lockx and also check if item is available on sql server side 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.SampleProductDTO dtoSampleProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SampleProductDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SampleItemMngEntities context = CreateContext()) { SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id); if (dbItem == null) { notification.Message = "Sample Product not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoSampleProduct.ConcurrencyFlag))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2DB_SampleProduct(dtoSampleProduct, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.SampleProductID, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public bool UpdateQARemarkData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.SampleQARemarkDTO dtoRemark = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SampleQARemarkDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SampleItemMngEntities context = CreateContext()) { SampleProduct dbProduct = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == dtoRemark.SampleProductID); if (dbProduct == null) { throw new Exception("Sample not found"); } SampleQARemark dbItem = new SampleQARemark(); dbProduct.SampleQARemark.Add(dbItem); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; converter.DTO2DB_SampleQARemark(dtoRemark, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId); //// notification //SendNotification(context); // update context.SaveChanges(); int newID = dbItem.SampleQARemarkID; dtoItem = converter.DB2DTO_SampleQARemark(context.SampleItemMng_SampleQARemark_View.Include("SampleItemMng_SampleQARemarkImage_View").FirstOrDefault(o => o.SampleQARemarkID == newID)); return(true); } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }