public async Task <IActionResult> Create([FromQuery(Name = "audio")] uint audioOwnerId, [FromQuery(Name = "category")] uint categoryId, string redirect = null) { var authEntry = HttpContext.GetAuthEntry(); if (authEntry is null) { return(Redirect("/login")); } var audioOwner = await audioOwnerRepo.GetById(audioOwnerId); var category = await categoryRepo.GetCategory(categoryId); // Ensure that audioOwner and category have the same ownerId if (audioOwner.OwnerId != category.OwnerId) { return(BadRequest()); } // ensure the user has permissions to edit the guild var userGuilds = await userService.GetAllowedUserGuilds(authEntry); if (!userGuilds.Any(x => x.Id == audioOwner.OwnerId)) { return(Unauthorized()); } await audioCategoryRepo.Create(audioOwnerId, categoryId); return(string.IsNullOrWhiteSpace(redirect) ? LocalRedirect("/") : LocalRedirect(redirect)); }
public IActionResult AddDocument([FromBody] AddDocumentModel addDocumentModel) { //1. Validate Model if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //2. Validate category if (addDocumentModel.CategoryId.HasValue) { var currentCategory = _categoryRepo.GetCategory(addDocumentModel.CategoryId.Value); if (currentCategory == null) { return(NotFound("CategoryNotExist")); } } //3. If category id valid, start update document Document newDocument = new Document() { CategoryId = addDocumentModel.CategoryId, Title = addDocumentModel.Title, Description = addDocumentModel.Description, Cover = addDocumentModel.Cover, PublishYear = addDocumentModel.PublishYear }; var response = _documentRepo.AddDocument(newDocument); return(Ok(response)); }
public IActionResult GetCategory(int id) { var obj = _repo.GetCategory(id); if (obj == null) { return(NotFound(new { message = "Category with this id isn't exist in database" })); } var objDto = _mapper.Map <CategoryDto>(obj); return(Ok(objDto)); }
// GET: Categories/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var category = _repo.GetCategory((int)id); if (category == null) { return(new HttpNotFoundResult()); } return(View(category)); }
public async Task <CategoryIndexModel> Category(string id) { var model = await _categoryRepo.GetCategory(id); if (model == null) { return(null); } var user = new CategoryIndexModel { CategoryId = model.CategoryId, name = model.name }; return(user); }
public IActionResult Delete(int id) { var category = repo.GetCategory(id); repo.Delete(category); return(RedirectToAction("All")); }
public async Task <IActionResult> Upload([FromForm] IFormFile file, [FromForm] string name, [FromRoute] ulong server, [FromForm] List <uint> categories) { var token = new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token; var authEntry = HttpContext.GetAuthEntry(); if (authEntry is null) { return(Redirect("/login")); } var userGuilds = await userService.GetAllowedUserGuilds(authEntry); if (!userGuilds.Any(x => x.Id == server)) { return(Unauthorized()); } if (!IsValidName(name, out var cleanedName)) { return(BadRequest("Invalid quote name")); } var audio_owner = await audioProcessingService.Upload(file, server, authEntry.UserId, cleanedName, token); foreach (var categoryId in categories) { var category = await categoryRepo.GetCategory(categoryId); if (category != null && category.OwnerId == server) { await audioCategoryRepo.Create(audio_owner.Id, category.Id); } } return(RedirectToAction("Index", new { server })); }
public async Task <IActionResult> GetDelete([FromRoute] ulong server, [FromRoute] uint id) { var authEntry = (AuthEntry)HttpContext.Items["key"]; if (authEntry is null) { return(Redirect("/login")); } var userGuilds = await userService.GetAllowedUserGuilds(authEntry); var category = await categoryRepo.GetCategory(id); if (!userGuilds.Any(x => x.Id == server) || category.OwnerId != server) { return(Unauthorized()); } return(View("Delete", new DeleteViewModel(category, server))); }
public Category GetCategory(int id) { try { return(categoryRepo.GetCategory(id)); } catch (DALException ex) { throw new ServiceException($"DAL exception : {ex.Message}"); } }
public ActionResult Update(int Id) { CategoryVM categoryViewModel = new CategoryVM() { Category = _categoryRepo.GetCategory(Id), categoryOptions = _categoryRepo.GetCategoryOptions(Id), PageTitle = "Edit Category" }; return(View(categoryViewModel)); }
public IActionResult UpdateCategory([FromBody] UpdateCategoryModel updateCategoryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Category currentCategory = _categoryRepo.GetCategory(updateCategoryModel.Id); if (currentCategory == null) { return(NotFound("CategoryNotFound")); } Category updateCategory = new Category() { Id = updateCategoryModel.Id, Title = updateCategoryModel.Title }; var response = _categoryRepo.UpdateCategory(updateCategory); return(Ok(response)); }
public DataTable GetPagedArchives(int siteId, int?categoryId, int publisherId, bool includeChild, int flag, string keyword, string orderByField, bool orderAsc, int pageSize, int currentPageIndex, out int recordCount, out int pages) { var ic = _catRepo.GetCategory(siteId, categoryId ?? 0); int[] catIdArray; if (includeChild) { catIdArray = GetCatArrayByPath(ic); } else { catIdArray = new int[] { categoryId ?? 0 } }; return(_archiveQuery.GetPagedArchives(siteId, catIdArray, publisherId, includeChild, flag, keyword, orderByField, orderAsc, pageSize, currentPageIndex, out recordCount, out pages)); }
public Error Set(CmsCategoryEntity src) { if (src.ParentId != 0 && src.ParentId == value.ID) { return(new Error("父级栏目有误:与子栏目相同")); } if (value.ID <= 0) { if (src.SiteId <= 0) { return(new Error("参数错误:SiteId")); } if (string.IsNullOrEmpty(src.Tag)) { return(new Error("缺少参数:Tag")); } if (string.IsNullOrEmpty(src.Name)) { return(new Error("栏目名称不能为空")); } value.SiteId = src.SiteId; value.Code = src.Code ?? ""; value.Tag = src.Tag ?? ""; value.Icon = ""; value.Path = ""; value.Flag = 0; //todo: 初始化flag var maxSortNumber = _repo.GetMaxSortNumber(value.SiteId); if (maxSortNumber == 0) { maxSortNumber = 1; } value.SortNumber = maxSortNumber; _pathChanged = true; } if (src.Tag == "-") { return(new Error("不允许使用栏目保留Tag")); } if (src.ParentId == 0 && errTags.Contains(src.Tag)) { return(new Error("不允许使用保留栏目Tag")); } if (value.ParentId != src.ParentId) { if (src.ParentId > 0) { var ip = _repo.GetCategory(value.SiteId, src.ParentId); if (ip == null || ip.Get().SiteId != value.SiteId) { return(new Error("上级分类不存在")); } } value.ParentId = src.ParentId; _pathChanged = true; } if (string.IsNullOrEmpty(src.Tag)) { return(new Error("栏目tag不能为空")); } if (!_repo.CheckTagMatch(value.SiteId, value.ParentId, src.Tag, value.ID)) { return(new Error("分类TAG已存在")); } if (value.Tag != src.Tag) { _pathChanged = true; } value.Tag = src.Tag; value.Flag = src.Flag; value.ModuleId = src.ModuleId; value.Name = src.Name ?? ""; value.Icon = src.Icon ?? ""; value.Title = src.Title ?? ""; value.Keywords = src.Keywords ?? ""; value.Description = src.Description ?? ""; value.Location = src.Location ?? ""; if (string.IsNullOrEmpty(src.Location)) { value.Flag ^= (int)CategoryFlag.Redirect; } else { value.Flag |= (int)CategoryFlag.Redirect; } return(null); }
// GET: Category public ActionResult Index() { var category = _repo.GetCategory(); return(View(category)); }
public ActionResult <IEnumerable <Category> > GetCategory() { var categoryItems = _repository.GetCategory(); return(Ok(categoryItems)); }
// GET: Category public ActionResult Index() { var categories = _repo.GetCategory().AsNoTracking(); return(View(categories)); }