public IActionResult GetById([FromBody] NewCategoryModel model) { var token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", string.Empty); if (_userService.Validate(token) != null) { try { IEnumerable <NewTodo> todoList = _newTodoRepository.GetAllTodosById(model.Id); var todos = _mapper.Map <IEnumerable <NewTodo> >(todoList); return(Ok(new { todos })); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } } else { return(Unauthorized(new { message = "Invalid Token" })); } }
public IActionResult Create([FromBody] NewCategoryModel model) { var token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", string.Empty); if (_userService.Validate(token) != null) { var category = _mapper.Map <NewCategory>(model); try { _newCategoryRepository.AddCategory(category); _newCategoryRepository.Save(); IEnumerable <NewCategory> cates = _newCategoryRepository.GetAllCategoriesById(model.Owner); var categories = _mapper.Map <IEnumerable <NewCategoryModel> >(cates); //return new JsonResult(categories); return(Ok(new { categories })); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } } else { return(Unauthorized(new { message = "Invalid Token" })); } }
public async Task <IActionResult> AddCategory(NewCategoryModel model) { var categories = await _solutionApiClient.GetAllCategoriesAsync(); ViewBag.Categories = categories.Data; var dto = new NewCategoryDto { Name = model.Name, Description = model.Description, ParentCategoryId = model.ParentCategoryId }; var ph = model.Logo; byte[] p1 = null; using (var fs1 = ph.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } dto.Logo = new NewPhotoDto { Data = p1, Type = "Logo" }; await _solutionApiClient.AddCategoryAsync(dto); return(Redirect("addCategory")); }
public async Task <IActionResult> New(NewCategoryModel model) { if (!ModelState.IsValid) { return(View(model)); } var response = await _categoryService.InsertCategoryAsync(model); if (response.Success) { TempData["CategoryCreated"] = "Kategori başarıyla kaydedildi."; return(RedirectToAction(nameof(Index))); } switch (response.ErrorType) { case ErrorType.DuplicatedCategoryName: ViewData["NewCategoryError"] = "Bu kategori adı daha önce kullanılmıştır."; break; default: ViewData["NewCategoryError"] = "Kategori eklenemedi"; break; } return(View(model)); }
public async Task <ServiceResponse> InsertCategoryAsync(NewCategoryModel model) { if (model == null) { return(new ServiceResponse(false, ErrorType.NullModel)); } if (await _unitOfWork.CategoryRepository.FindOneAsync(x => x.Name == model.Name) != null) { return(new ServiceResponse(false, ErrorType.DuplicatedCategoryName)); } var entity = _mapper.Map <Category>(model); entity.Slug = model.Name.ConvertToSlugFormat(); if (model.ImageFile != null) { var suffix = Guid.NewGuid().ToString(); await _imageService.SaveCategoryImage(model.ImageFile, suffix); entity.ImageName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName) + "-" + suffix + Path.GetExtension(model.ImageFile.FileName); } await _unitOfWork.CategoryRepository.AddAsync(entity); return(new ServiceResponse(true)); }
public IActionResult Categories() { List <Category> dbCategories = dbContext.categories.ToList(); NewCategoryModel viewModel = new NewCategoryModel(); viewModel.allCategories = dbCategories; return(View("Categories", viewModel)); }
public async Task <IEnumerable <CreativeCategory> > SaveCategory(NewCategoryModel model) { if (model.Id == 0) { db.Categories.Add(new CreativeCategory { Name = model.Name }); } else { var editCategory = await db.Categories.Get(model.Id); editCategory.Name = model.Name; } db.Save(); return(db.Categories.GetAll()); }
public async Task <IHttpActionResult> SaveCategory(NewCategoryModel model) { return(Ok(await service.SaveCategory(model))); }