コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }