Example #1
0
        public async Task <IActionResult> CreateFile(FileViewModel model)
        {
            try
            {
                var user = _userManager.GetUserAsync(User).Result;
                var file = new Files()
                {
                    FileName   = model.FileName,
                    Type       = model.Type,
                    UserId     = user.Id,
                    CategoryId = model.CategoryId
                };
                if (!string.IsNullOrEmpty(model.Url))
                {
                    file.Url = model.Url;
                    _fileService.Insert(file);
                    return(Json(ResultStatus.ReturnTrue()));
                }
                if (model.File != null)
                {
                    file.Url = await UploadFileCategory(model.File, model.CategoryId ?? Guid.Empty);

                    _fileService.Insert(file);
                    return(Json(ResultStatus.ReturnTrue()));
                }
                return(Json(ResultStatus.ReturnFalse()));
            }
            catch (Exception ex)
            {
                return(Json(ResultStatus.ReturnFalse()));
            }
        }
Example #2
0
        public IActionResult PrioritizeFile(Guid id)
        {
            try
            {
                var file = _fileService.GetFile(id);
                file.IsPrioritize = !file.IsPrioritize;
                _fileService.Update(file);
                return(Json(ResultStatus.ReturnTrue()));

                //if (!file.IsPrioritize??false)
                //{
                //    var f = _fileService.GetAllFileByTypePrioritize(file.CategoryId??Guid.Empty, "Image",true);
                //    //if (f.Count()<=14)
                //    //{
                //        var user = _userManager.GetUserAsync(User).Result;
                //        file.IsPrioritize = !file.IsPrioritize;
                //        _fileService.Update(file);
                //        return Json(ResultStatus.ReturnTrue());
                //    //}
                //    //else
                //    //{
                //    //    return Json( new
                //    //    {
                //    //        Result = true,
                //    //        Message = "Ưu tiên đã hết. Vui lòng tắt ưu tiên khác"
                //    //    });
                //    //}
                //}
                return(Json(ResultStatus.ReturnFalse()));
            }
            catch (Exception ex)
            {
                return(Json(ResultStatus.ReturnFalse()));
            }
        }
Example #3
0
 public IActionResult PublicFile(Guid id)
 {
     try
     {
         var file = _fileService.GetFile(id);
         var user = _userManager.GetUserAsync(User).Result;
         file.IsPublic = !file.IsPublic;
         _fileService.Update(file);
         return(Json(ResultStatus.ReturnTrue()));
     }
     catch (Exception ex)
     {
         return(Json(ResultStatus.ReturnFalse()));
     }
 }
Example #4
0
 public IActionResult CreateCategory(CategoryModel model)
 {
     try
     {
         var cate = new Category()
         {
             Name        = model.Name,
             CategoryId  = model.CategoryId,
             Description = model.Description,
         };
         _categoryService.Add(cate);
         return(Json(ResultStatus.ReturnTrue()));
     }
     catch (Exception ex)
     {
         return(Json(ResultStatus.ReturnFalse()));
     }
 }
Example #5
0
 public IActionResult UpdateFile(FileViewModel model)
 {
     try
     {
         var file = _fileService.GetFile(model.Id);
         var user = _userManager.GetUserAsync(User).Result;
         file.FileName   = model.FileName;
         file.Url        = model.Url;
         file.Type       = model.Type;
         file.UserId     = user.Id;
         file.CategoryId = model.CategoryId;
         _fileService.Update(file);
         return(Json(ResultStatus.ReturnTrue()));
     }
     catch (Exception ex)
     {
         return(Json(ResultStatus.ReturnFalse()));
     }
 }
Example #6
0
 public IActionResult UpdateCategory(CategoryModel model)
 {
     try
     {
         var cate = _categoryService.GetId(model.Id);
         if (cate.Name != model.Name)
         {
             cate.Name = model.Name;
             _categoryService.UpdateName(cate);
             return(Json(ResultStatus.ReturnTrue()));
         }
         cate.CategoryId  = model.CategoryId;
         cate.Description = model.Description;
         _categoryService.Update(cate);
         return(Json(ResultStatus.ReturnTrue()));
     }
     catch (Exception ex)
     {
         return(Json(ResultStatus.ReturnFalse()));
     }
 }