Exemplo n.º 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);
            }
        }