Esempio n. 1
0
        // update Factory Sale Quotation
        public void updateFactorySaleQuotation(DTO.FactorySaleQuotationDTO dtoItem, ref FactorySaleQuotation dbItem)
        {
            //Update Factory Sale Quotation Detail
            if (dtoItem.LstFactorySaleQuotationDetail != null)
            {
                foreach (FactorySaleQuotationDetail item in dbItem.FactorySaleQuotationDetail.ToArray())
                {
                    if (!dtoItem.LstFactorySaleQuotationDetail.Select(x => x.FactorySaleQuotationDetailID).Contains(item.FactorySaleQuotationDetailID))
                    {
                        dbItem.FactorySaleQuotationDetail.Remove(item);
                    }
                }
                foreach (DTO.FactorySaleQuotationDetailDTO dto in dtoItem.LstFactorySaleQuotationDetail)
                {
                    FactorySaleQuotationDetail item;
                    if (dto.FactorySaleQuotationDetailID <= 0)
                    {
                        item = new FactorySaleQuotationDetail();
                        dbItem.FactorySaleQuotationDetail.Add(item);
                    }
                    else
                    {
                        item = dbItem.FactorySaleQuotationDetail.FirstOrDefault(s => s.FactorySaleQuotationDetailID == dto.FactorySaleQuotationDetailID);
                    }
                    if (item != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactorySaleQuotationDetailDTO, FactorySaleQuotationDetail>(dto, item);
                    }
                }
            }
            //update Factory Sale Quotation Attached file
            if (dtoItem.LstFactorySaleQuotationAttachedFile != null)
            {
                foreach (FactorySaleQuotationAttachedFile item in dbItem.FactorySaleQuotationAttachedFile.ToArray())
                {
                    if (!dtoItem.LstFactorySaleQuotationAttachedFile.Select(x => x.FactorySaleQuotationAttachedFileID).Contains(item.FactorySaleQuotationAttachedFileID))
                    {
                        dbItem.FactorySaleQuotationAttachedFile.Remove(item);
                    }
                }
                foreach (var item in dtoItem.LstFactorySaleQuotationAttachedFile)
                {
                    FactorySaleQuotationAttachedFile dbAttachedFile;
                    if (item.FactorySaleQuotationAttachedFileID < 0)
                    {
                        dbAttachedFile = new FactorySaleQuotationAttachedFile();
                        dbItem.FactorySaleQuotationAttachedFile.Add(dbAttachedFile);
                    }
                    else
                    {
                        dbAttachedFile = dbItem.FactorySaleQuotationAttachedFile.Where(o => o.FactorySaleQuotationAttachedFileID == item.FactorySaleQuotationAttachedFileID).FirstOrDefault();
                    }
                    if (dbAttachedFile != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactorySaleQuotationAttachedFileDTO, FactorySaleQuotationAttachedFile>(item, dbAttachedFile);
                    }
                }
            }

            AutoMapper.Mapper.Map <DTO.FactorySaleQuotationDTO, FactorySaleQuotation>(dtoItem, dbItem);
        }
Esempio n. 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.FactorySaleQuotationDTO dtoFactorySaleQuotation = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySaleQuotationDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                if (dtoFactorySaleQuotation.FactoryRawMaterialID == null)
                {
                    notification.Type    = NotificationType.Error;
                    notification.Message = "Customer not exist";
                    return(false);
                }

                using (FactorySalesQuotationMngEntities context = CreateContext())
                {
                    FactorySaleQuotation dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactorySaleQuotation();
                        context.FactorySaleQuotation.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactorySaleQuotation.FirstOrDefault(o => o.FactorySaleQuotationID == id);
                    }
                    // process Attached files
                    foreach (FactorySaleQuotationAttachedFileDTO dtoattachedFile in dtoFactorySaleQuotation.LstFactorySaleQuotationAttachedFile)
                    {
                        if (dtoattachedFile.OtherFileHasChange)
                        {
                            if (string.IsNullOrEmpty(dtoattachedFile.NewOtherFile))
                            {
                                fwFactory.RemoveFile(dtoattachedFile.OtherFile);
                            }
                            else
                            {
                                dtoattachedFile.FileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoattachedFile.NewOtherFile, dtoattachedFile.OtherFile, dtoattachedFile.OtherFileFriendlyName);
                            }
                        }
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "Factory Sale Quotation not found!";
                        return(false);
                    }


                    else
                    {
                        ///convert dto to db
                        var userInformation = _AccountMngFactory.GetUserInformation(userId, out notification);
                        converter.updateFactorySaleQuotation(dtoFactorySaleQuotation, ref dbItem);
                        context.FactorySaleQuotationDetail.Local.Where(o => o.FactorySaleQuotation == null).ToList().ForEach(o => context.FactorySaleQuotationDetail.Remove(o));
                        context.FactorySaleQuotationAttachedFile.Local.Where(o => o.FactorySaleQuotation == null).ToList().ForEach(o => context.FactorySaleQuotationAttachedFile.Remove(o));
                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;
                        dbItem.FactorySaleQuotationStatusID = 1;
                        dbItem.DocumentDate     = dtoFactorySaleQuotation.DocumentDate.ConvertStringToDateTime();
                        dbItem.ExpectedPaidDate = dtoFactorySaleQuotation.ExpectedPaidDate.ConvertStringToDateTime();
                        dbItem.CreatedDate      = dtoFactorySaleQuotation.CreatedDate.ConvertStringToDateTime();
                        dbItem.ValidUntil       = dtoFactorySaleQuotation.ValidUntil.ConvertStringToDateTime();
                        if (userInformation != null)
                        {
                            dbItem.CompanyID = userInformation.CompanyID;
                        }
                        // Generate FactorySaleQuotationUD.
                        if (id == 0)
                        {
                            dbItem.FactorySaleQuotationUD = context.FactorySaleQuotationMng_function_GenerateFactorySaleQuotationUD(dbItem.CreatedDate.Value.Year, dbItem.CreatedDate.Value.Month).FirstOrDefault();
                        }
                        context.SaveChanges();

                        dtoItem = GetData(userId, dbItem.FactorySaleQuotationID, out notification).Data;

                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Message = ex.Message;
                notification.Type    = Library.DTO.NotificationType.Error;
                return(false);
            }
        }