Exemplo n.º 1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (CatalogFileMngEntities context = CreateContext())
                {
                    CatalogFile dbItem = context.CatalogFile.FirstOrDefault(o => o.CatalogFileID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Catalog file not found!");
                    }

                    // remove file
                    if (!string.IsNullOrEmpty(dbItem.FileUD))
                    {
                        fwFactory.RemoveFile(dbItem.FileUD);
                    }
                    context.CatalogFile.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
 public void DTO2DB(DTO.CatalogFileDTO dtoItem, ref CatalogFile dbItem, string TmpFile, int userId)
 {
     // employee
     AutoMapper.Mapper.Map <DTO.CatalogFileDTO, CatalogFile>(dtoItem, dbItem);
     if (dtoItem.HasChanged)
     {
         dbItem.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.NewFile, dbItem.FileUD, dtoItem.FriendlyName);
     }
     if (dtoItem.PLHasChanged)
     {
         dbItem.PriceListFileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.PLNewFile, dbItem.PriceListFileUD, dtoItem.PLFriendlyName);
     }
 }
Exemplo n.º 3
0
 public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
 {
     DTO.CatalogFileDTO dtoCatalogFile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.CatalogFileDTO>();
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (CatalogFileMngEntities context = CreateContext())
         {
             CatalogFile dbItem = context.CatalogFile.FirstOrDefault(o => o.CatalogFileID == id);
             if (id > 0)
             {
                 dbItem = context.CatalogFile.FirstOrDefault(o => o.CatalogFileID == id);
             }
             else
             {
                 dbItem = new CatalogFile();
                 context.CatalogFile.Add(dbItem);
             }
             if (dbItem == null)
             {
                 throw new Exception("Catalog file not found!");
             }
             dbItem.UpdatedBy   = userId;
             dbItem.UpdatedDate = DateTime.Now;
             converter.DTO2DB(dtoCatalogFile, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);
             context.SaveChanges();
             dtoItem = this.GetData(dbItem.CatalogFileID, out notification).Data;
             return(true);
         }
     }
     catch (Exception ex)
     {
         notification = new Library.DTO.Notification()
         {
             Message = ex.Message, Type = Library.DTO.NotificationType.Error
         };
         return(false);
     }
 }