public async Task<IHttpActionResult> AddCategory(CategoryModel model) { try { var userId = User.Identity.GetUserId(); var category = new DrNajeeb.EF.Category(); category.Name = model.Name; category.IsShowOnFrontPage = model.IsShowOnFrontPage ?? false; category.SEOName = Helpers.URLHelpers.URLFriendly(model.Name); category.CreatedOn = DateTime.UtcNow; category.CreatedBy = userId; category.Active = true; var maxValue = await _Uow._Categories.GetAll(x => x.Active == true).OrderByDescending(x => x.DisplayOrder).FirstOrDefaultAsync(); category.DisplayOrder = (maxValue != null) ? maxValue.DisplayOrder + 1 : 1; //todo : set and save category url //set display order of categories await LogHelpers.SaveLog(_Uow, "Add Category " + model.Name, userId); _Uow._Categories.Add(category); await _Uow.CommitAsync(); return Ok(); } catch (Exception ex) { return InternalServerError(ex); } }
public async Task<IHttpActionResult> GetSingle(int Id) { try { var category = await _Uow._Categories.GetByIdAsync(Id); if (category == null) { return NotFound(); } var model = new CategoryModel(); model.CategoryURL = category.CategoryURL; model.Id = category.Id; model.ImageURL = category.ImageURL; model.Name = category.Name; model.IsShowOnFrontPage = category.IsShowOnFrontPage; model.SeoName = category.SEOName; var userId = User.Identity.GetUserId(); //await LogHelpers.SaveLog(_Uow, "View Category " + category.Name, userId); return Ok(model); } catch (Exception ex) { return InternalServerError(ex); } }
public async Task<IHttpActionResult> UpdateCategory(CategoryModel model) { try { var userId = User.Identity.GetUserId(); var category = await _Uow._Categories.GetByIdAsync(model.Id); category.Name = model.Name; category.IsShowOnFrontPage = model.IsShowOnFrontPage ?? false; category.SEOName = Helpers.URLHelpers.URLFriendly(model.Name); category.UpdatedOn = DateTime.Now; category.UpdatedBy = userId; //todo : add useid in updatedby _Uow._Categories.Update(category); await LogHelpers.SaveLog(_Uow, "Update Category " + category.Name, userId); await _Uow.CommitAsync(); return Ok(); } catch (Exception ex) { return InternalServerError(ex); } }