Ejemplo n.º 1
0
 public void DTO2DB(DTO.PriceListFile dtoItem, ref PriceListFile dbItem)
 {
     AutoMapper.Mapper.Map <DTO.PriceListFile, PriceListFile>(dtoItem, dbItem);
     dbItem.UpdatedDate = DateTime.Now;
 }
Ejemplo n.º 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.PriceListFile dtoPriceListFile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PriceListFile>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            List <DTO.PriceListFile> PriceListFileDTOs = new List <DTO.PriceListFile>();

            try
            {
                using (PriceListFileEntities context = CreateContext())
                {
                    PriceListFile dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new PriceListFile();
                        context.PriceListFile.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.PriceListFile.FirstOrDefault(o => o.PriceListFileID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Data not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoPriceListFile.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        // processing pdf
                        if (dtoPriceListFile.PDFFileLocation_HasChange)
                        {
                            if (string.IsNullOrEmpty(dtoPriceListFile.NewPDFFile))
                            {
                                fwFactory.RemoveFile(dtoPriceListFile.PDFFileUD);
                            }
                            else
                            {
                                dtoPriceListFile.PDFFileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoPriceListFile.NewPDFFile, dtoPriceListFile.PDFFileUD, dtoPriceListFile.PDFFriendlyName);
                            }
                        }

                        // processing excel
                        if (dtoPriceListFile.ExcelFileLocation_HasChange)
                        {
                            if (string.IsNullOrEmpty(dtoPriceListFile.NewExcelFile))
                            {
                                fwFactory.RemoveFile(dtoPriceListFile.ExcelFileUD);
                            }
                            else
                            {
                                dtoPriceListFile.ExcelFileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoPriceListFile.NewExcelFile, dtoPriceListFile.ExcelFileUD, dtoPriceListFile.ExcelFriendlyName);
                            }
                        }
                        converter.DTO2DB(dtoPriceListFile, ref dbItem);

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();

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

                        return(true);
                    }
                }
            }

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