コード例 #1
0
ファイル: TodoController.cs プロジェクト: ashn01/todoList
        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" }));
            }
        }
コード例 #2
0
ファイル: CategoryController.cs プロジェクト: ashn01/todoList
        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" }));
            }
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public IActionResult Categories()
        {
            List <Category>  dbCategories = dbContext.categories.ToList();
            NewCategoryModel viewModel    = new NewCategoryModel();

            viewModel.allCategories = dbCategories;
            return(View("Categories", viewModel));
        }
コード例 #7
0
ファイル: AdminService.cs プロジェクト: drontik/maybe
        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());
        }
コード例 #8
0
 public async Task <IHttpActionResult> SaveCategory(NewCategoryModel model)
 {
     return(Ok(await service.SaveCategory(model)));
 }