Esempio n. 1
0
        public IActionResult Put(int id, [FromBody] CreateCategoryDto category)
        {
            category.CategoryId = id;
            try
            {
                _editCategoryCommand.Execute(category);
                return(NoContent());
            }
            catch (EntityNotFoundException e)
            {
                if (e.Message == "Category doesn't exist.")
                {
                    return(NotFound(e.Message));
                }

                return(UnprocessableEntity(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }
Esempio n. 2
0
        public HttpStatusCode CreateCategory(CreateCategoryDto createCategoryDto)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(HttpStatusCode.Unauthorized);
            }

            var response = _categoryRepository.CreateCategory(createCategoryDto, userId);

            switch (response)
            {
            case HttpStatusCode.OK:
                return(HttpStatusCode.OK);

            case HttpStatusCode.InternalServerError:
                return(HttpStatusCode.InternalServerError);

            default:
                return(HttpStatusCode.NotFound);
            }
        }
 public FindCategoryDto Post([FromBody] CreateCategoryDto cat)
 {
     return(categoriesServices.PostCategory(cat));
 }
        public ActionResult Create([FromRoute] string name, [FromBody] CreateCategoryDto dto)
        {
            var id = _categoryService.Create(name, dto);

            return(Created($"/api/Game/Category/{id}", null));
        }
        public async Task <IActionResult> AddCategory(CreateCategoryDto categoryDto)
        {
            var response = await _categoryService.Add(categoryDto);

            return(GetInstanceActionResult(response));
        }
 public async Task <IActionResult> Post([FromBody] CreateCategoryDto dto)
 {
     return(Ok(await Mediator.Send(dto)));
 }
 /// <summary>
 /// Transforme un createdCategorie DTO en model
 /// </summary>
 /// <param name="cat">le createCategoryDto</param>
 /// <returns>Categorie</returns>
 private Category TransformDtoToModel(CreateCategoryDto cat)
 {
     return(new Category(null, cat.NameCategory));
 }
 public async Task CreateAsync(CreateCategoryDto input)
 {
     var category = ObjectMapper.Map <Category>(input);
     await _categoryManager.CreateAsync(category);
 }
Esempio n. 9
0
 public static CreateCategoryViewModel GetCreateCategoryViewModel(CreateCategoryDto createCategoryDto)
 {
     return(new CreateCategoryViewModel(createCategoryDto.Title));
 }
Esempio n. 10
0
 public Task <OperationResult <int> > CreateCategory(CreateCategoryDto createCategoryDto)
 {
     return(categoryService.CreateCategory(createCategoryDto.Name));
 }
Esempio n. 11
0
        public async Task <IActionResult> Create([FromBody] CreateCategoryDto input)
        {
            await _categoryService.CreateCategories(input);

            return(Ok());
        }
Esempio n. 12
0
 public async Task <IActionResult> Create([FromBody] CreateCategoryDto dto)
 => await GetResponse(async() =>
                      new ApiResponseViewModel(true, "Category Created Successfully",
                                               await _categoryService.Create(dto, UserId)));
Esempio n. 13
0
 public async Task CreateCategories(CreateCategoryDto input)
 {
     //Admin: Yeni Kategori Oluşturma
     var category = _mapper.Map <Category>(input);
     await _repository.InsertAsync(category);
 }
Esempio n. 14
0
        public ActionResult CreateCategory([FromBody] CreateCategoryDto newCategoryDto)
        {
            var id = _categoryService.CreateCategory(newCategoryDto);

            return(Created($"/category/{id}", null));
        }
 public FindCategoryDto Put(int id, [FromBody] CreateCategoryDto cat)
 {
     return(categoriesServices.PutCategory(id, cat));
 }
Esempio n. 16
0
        public ActionResult <CategoryDto> CreateCategory(Guid personId, Guid projectId, [FromBody] CreateCategoryDto dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                if (!_db.Person.BelongsToUser(personId, HttpContext))
                {
                    return(Forbid());
                }
                if (_db.Participation.GetRole(personId, projectId)?.CalendarWrite != true)
                {
                    return(Forbid());
                }

                var category = _mapper.Map <Category>(dto);
                category.ProjectId = projectId;

                foreach (var eligibility in category.Eligibilities)
                {
                    var role = _db.Role
                               .FindByCondition(x => x.Id == eligibility.RoleId && x.ProjectId == projectId)
                               .SingleOrDefault();
                    if (role == null)
                    {
                        return(BadRequest());
                    }

                    eligibility.ShiftsWrite         = eligibility.ShiftsWrite && eligibility.ShiftsRead;
                    eligibility.IsTeamCaptain       = eligibility.IsTeamCaptain && eligibility.ShiftsRead;
                    eligibility.IsSubstituteCaptain = eligibility.IsSubstituteCaptain && eligibility.ShiftsRead && !eligibility.IsTeamCaptain;
                }

                _db.Category.Create(category);
                _db.Save();

                var createdCategory = _db.Category
                                      .FindByCondition(x => x.Id == category.Id && x.ProjectId == projectId)
                                      .Include(x => x.Eligibilities).ThenInclude(x => x.Role)
                                      .SingleOrDefault();

                return(Ok(_mapper.Map <CategoryDto>(createdCategory)));
            }
            catch (Exception e)
            {
                _logger.LogError($"ERROR in CreateCategory: {e.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Esempio n. 17
0
 public CreateCategoryCommand(CreateCategoryDto createCategoryDto)
 {
     CreateCategoryDto = createCategoryDto;
 }
Esempio n. 18
0
        public async Task <Response> Add(CreateCategoryDto categoryDto)
        {
            var AddCategoryCommand = ObjectMapper.Mapper.Map <DDDNLayer.Application.Commands.AddCategoryCommand>(categoryDto);

            return(await _mediatorHandler.SendCommand(AddCategoryCommand));
        }
Esempio n. 19
0
        public async Task <IActionResult> CreateCategory(CreateCategoryDto createCategoryDto)
        {
            var result = await categoryOrchestrator.CreateCategory(createCategoryDto);

            return(ActionResult(result));
        }
        public async Task <IActionResult> CreateCategory(CreateCategoryDto createCategoryDTO)
        {
            var categoryDto = await categoryService.CreateCategoryAsync(createCategoryDTO);

            return(CreatedAtAction(nameof(CreateCategory), categoryDto));
        }
Esempio n. 21
0
        public void DeleteCategoryTest()
        {
            CreateCategoryDto myDeleteExceptionCategory = new CreateCategoryDto();

            Task.WaitAll(Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => _CategoriesService.Delete(-1), "Id cannot be lower than 1."));
        }