示例#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);
        }
示例#2
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);
     }
 }