Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #3
0
        public bool UpdateProgressData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.SampleProgressDTO dtoProgress = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SampleProgressDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SampleItemMngEntities context = CreateContext())
                {
                    SampleProgress dbItem = null;
                    if (id <= 0)
                    {
                        dbItem = new SampleProgress();
                        context.SampleProgress.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SampleProgress.FirstOrDefault(o => o.SampleProgressID == id);
                    }
                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;

                    if (dbItem == null)
                    {
                        notification.Message = "Sample Progress not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_SampleProgress(dtoProgress, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);

                        //// notification
                        //SendNotification(context);

                        // remove orphan
                        context.SampleProgressImage.Local.Where(o => o.SampleProgress == null).ToList().ForEach(o => context.SampleProgressImage.Remove(o));
                        context.SaveChanges();

                        int newID = dbItem.SampleProgressID;
                        dtoItem = converter.DB2DTO_SampleProgress(context.SampleItemMng_SampleProgress_View.Include("SampleItemMng_SampleProgressImage_View").FirstOrDefault(o => o.SampleProgressID == newID));
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(false);
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        public bool DeleteQARemark(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SampleItemMngEntities context = CreateContext())
                {
                    // check if can delete
                    SampleQARemark dbItem = context.SampleQARemark.FirstOrDefault(o => o.SampleQARemarkID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Remark not found");
                    }

                    // everything ok, delete
                    // remove attached file
                    foreach (SampleQARemarkImage dbImage in dbItem.SampleQARemarkImage.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbImage.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbImage.FileUD);
                        }
                        dbItem.SampleQARemarkImage.Remove(dbImage);
                    }
                    context.SampleQARemarkImage.Local.Where(o => o.SampleQARemark == null).ToList().ForEach(o => context.SampleQARemarkImage.Remove(o));
                    context.SampleQARemark.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }