コード例 #1
0
        public async Task <OperationResultDTO <string> > CreateAsync(CreateTshirtDTO model, string email)
        {
            var result = new OperationResultDTO <string>();
            var user   = await _userManager.FindByEmailAsync(email);

            var category = await _categoryService.FindCategoryAsync(c => c.Name == model.Category, false);

            var gender = await _genderService.FindGenderAsync(c => c.Name == model.Gender, false);

            try
            {
                var shirt = new TShirt
                {
                    Name        = model.Name,
                    Description = model.Description,
                    PictureUrl  = model.PictureUrl,
                    Price       = model.Price,
                    UserId      = user.Id,
                    CategoryId  = category.Id,
                    GenderId    = gender.Id,
                    CreateDate  = DateTime.Now
                };

                _repositoryManager.Tshirt.CreateTShirt(shirt);
                await _repositoryManager.SaveAsync();

                result.Success = true;
                result.Message = "New t-shirt has been created";

                return(result);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "There is something wrong";
                result.Data    = ex.Message;

                return(result);
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create(CreateTshirtDTO model)
        {
            if (model is null)
            {
                _logger.LogError("CreateTshirtDTO object send from client is null");

                return(BadRequest("CreateTshirtDTO object is null"));
            }

            var email  = GetEmailFromHttpContextAsync();
            var tshirt = await _tshirtService.CreateAsync(model, email);

            if (!tshirt.Success)
            {
                _logger.LogError("Tshirt was not be created");

                return(BadRequest("Tshirt was not be created"));
            }
            _logger.LogInfo("Create a new t-shirt.");

            return(Ok(tshirt));
        }