public IActionResult Create(BrandCreate model)
 {
     if (ModelState.IsValid)
     {
         var brand = new Brand()
         {
             BrandName  = model.BrandName,
             IsDelete   = false,
             CategoryId = model.CategoryId
         };
         var fileName = string.Empty;
         if (model.BrandImg != null)
         {
             string uploadFolder = Path.Combine(webHostEnvironment.WebRootPath, "images/Brand");
             fileName = $"{Guid.NewGuid()}_{model.BrandImg.FileName}";
             var filePath = Path.Combine(uploadFolder, fileName);
             using (var fs = new FileStream(filePath, FileMode.Create))
             {
                 model.BrandImg.CopyTo(fs);
             }
         }
         brand.ImagePath = fileName;
         brandRepository.Create(brand);
         return(RedirectToAction("Index", "Product"));
     }
     return(View());
 }
        public async Task <IActionResult> Create([FromBody] BrandCreateDTO brandDTO)
        {
            var location = GetControllerActionName();

            try
            {
                logger.LogInfo($"{location}: Create Brand");
                if (brandDTO == null)
                {
                    logger.LogWarn($"{location}: Brand object is empty");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    logger.LogWarn($"{location}: Brand object is incomplete");
                    return(BadRequest(ModelState));
                }
                var brand     = mapper.Map <Brand>(brandDTO);
                var isSuccess = await brandRepository.Create(brand);

                if (!isSuccess)
                {
                    InternalError($"{location}: Create Brand failed");
                }
                logger.LogInfo($"{location}: Create Brand successful");
                return(Created("Create", new { brand }));
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }
示例#3
0
        public bool Create(BrandCreateRequest entity)
        {
            string name    = entity.Name;
            string address = entity.Address;
            string phone   = entity.Phone;
            string website = entity.Website;

            if (!util.ValidRangeLengthInput(name, 1, 100) ||
                !util.ValidRangeLengthInput(address, 1, 250) ||
                !util.ValidRangeLengthInput(website, 1, 100) ||
                !util.ValidFixedLengthInput(phone, 10))
            {
                return(false);
            }

            Brand exsited = _repo.GetAll().FirstOrDefault(e => e.Name.ToLower().Equals(name.Trim().ToLower()));

            if (exsited != null)
            {
                return(false);
            }

            Brand newEntity = new Brand();

            newEntity.Name    = name.Trim();
            newEntity.Address = address.Trim();
            newEntity.Phone   = phone.Trim();
            newEntity.Website = website.Trim();

            return(_repo.Create(newEntity));
        }
示例#4
0
            /// <summary>
            /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/>
            /// </summary>
            public async Task <int> Handle(Request request, CancellationToken cancellationToken)
            {
                int response = 0;

                try
                {
                    BrandModel model = await _BrandRepository.GetByName(request.Name);

                    if (model == null)
                    {
                        BrandInfo brand = new BrandInfo
                        {
                            Name = request.Name
                        };

                        await _BrandRepository.Create(brand);

                        await _BrandRepository.Save();

                        response = brand.Id;
                    }
                    else
                    {
                        response = model.Id;
                    }
                }
                catch (Exception ex)
                {
                    CommandExceptionHandler.Handle(ex, request);
                }

                return(response);
            }
示例#5
0
        public IActionResult CreateBrand([FromBody] BrandAggregate brandDto)
        {
            var brand = new Brand(brandDto.Name, brandDto.CountryCode);

            _brandRepository.Create(brand);

            return(Ok($"Brand {brand.Name} has ID: {brand.Id}"));
        }
示例#6
0
 public async Task <ActionResult <Brand> > Create([FromBody] Brand brand)
 {
     if (string.IsNullOrEmpty(brand.Title))
     {
         return(BadRequest());
     }
     _brandRepository.Create(brand);
     return(CreatedAtAction("Get", new { title = brand.Title }, brand));
 }
示例#7
0
        public IActionResult Create(Brand newBrand)
        {
            if (ModelState.IsValid)
            {
                brandRepository.Create(newBrand);
                return(RedirectToAction("Index", "BrandsManager"));
            }

            return(View());
        }
        public async Task <IActionResult> CreateBrand(BrandCreationDto dto)
        {
            var newBrand = new BrandCreationDto
            {
                Name = dto.Name
            };

            await _brandRepository.Create(newBrand);

            return(Ok(dto));
        }
        public IActionResult Create(Brand brand)
        {
            if (!ModelState.IsValid)
            {
                return(View(brand));
            }

            _brandRepository.Create(brand);

            return(RedirectToAction(nameof(List)));
        }
示例#10
0
 public IActionResult Create(Brand brand)
 {
     if (ModelState.IsValid)
     {
         var result = brandRepository.Create(brand);
         if (result > 0)
         {
             return(RedirectToAction("Index", "Brand"));
         }
     }
     ViewData["Message"] = "Thương hiệu đã tồn tại";
     return(View());
 }
示例#11
0
        public CreateBrandResponse CreateBrand(CreateBrandRequest request)
        {
            CreateBrandResponse response = new CreateBrandResponse();

            try
            {
                Brand brand = request.ConvertToBrand();
                brandRepository.Create(brand);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
示例#12
0
        public async Task <string> Create([FromBody] string json)
        {
            var    parser = new Parser(json);
            string name   = parser.AsString("BrandName");

            await _brandRepository.Create(name);

            var result = new
            {
                Result = true
            };

            return(JsonConvert.SerializeObject(result, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
        }
示例#13
0
        public async Task <IActionResult> Create(Brand brand)
        {
            if (brand == null)
            {
                return(BadRequest());
            }

            var _brand = _brandRepository.GetAll().Result.FirstOrDefault(x => x.Description == brand.Description);

            if (_brand != null)
            {
                ModelState.AddModelError("description", "La marca ya existe");
                return(BadRequest(ModelState));
            }

            var newbrand = new Brand()
            {
                Description = brand.Description
            };
            await _brandRepository.Create(newbrand);

            return(Ok(newbrand));
        }
示例#14
0
 public bool Create(BrandModel model)
 {
     return(_res.Create(model));
 }
示例#15
0
 public Brand Insert(Brand brand)
 {
     return(_brandRepository.Create(brand));
 }
示例#16
0
 public void Create(Brand entity)
 {
     _brandRepository.Create(entity);
 }
 public void CreateBrand(Brand brand)
 {
     _brandRepository.Create(brand);
 }