public async Task <IActionResult> AddBrand([FromBody] AppBrand model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    logger.LogInformation("Adding Brand in Repository");
                    var addedBrand = await BrandRepo.AddBrand(model);

                    if (addedBrand != null)
                    {
                        return(Ok(addedBrand));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception excp)
                {
                    logger.LogError("Error Adding Brand in Repository " + excp.Message);

                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }
 public ActionResult AddBrand(Brand brand)
 {
     if (!ModelState.IsValid)
     {
         return(View(brand));
     }
     _brandRepository.AddBrand(brand);
     return(RedirectToAction(nameof(List)));
 }
Ejemplo n.º 3
0
 public Brand CreateBrand(Brand brand)
 {
     if (brand != null)
     {
         this.Validator.ValidateBrand(brand);
         return(BrandRepository.AddBrand(brand));
     }
     return(null);
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostBrand([FromBody] Brand brand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await brandRepository.AddBrand(brand);

            return(CreatedAtAction("GetBrand", new { id = brand.BrandId }, brand));
        }
Ejemplo n.º 5
0
 public async Task <Brand> AddBrand(Brand brand)
 {
     try
     {
         return(await _brandRepository.AddBrand(brand));
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,BrandImage,ImageFile")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                brand.Id         = Guid.NewGuid();
                brand.BrandImage = await fileManager.UploadImage(brand.ImageFile);

                _repo.AddBrand(brand);
                await _repo.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
Ejemplo n.º 7
0
        public async Task <BrandViewModel> AddBrand(BrandViewModel model)
        {
            var brand = await _brandRepository.GetBrandType(model.UserId, model.Name);

            if (brand != null)
            {
                throw new UniventoryDomainException($"Brand already exist with name : {model.Name}");
            }

            var brandItem = new ProductBrand(model.UserId, model.Name, model.Description);
            var result    = _mapper.Map <ProductBrand, BrandViewModel>(_brandRepository.AddBrand(brandItem));
            await _brandRepository.UnitOfWork.SaveEntitiesAsync();

            return(result);
        }
Ejemplo n.º 8
0
 public HttpResponseMessage CreateBrand([FromBody] BrandViewModel model)
 {
     try
     {
         var data = brandrepository.AddBrand(model);
         if (data != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = model, message = "The record has been created successfully" }));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "There was an error creating the record" }));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = $"There was an error creating the record" }));
     }
 }
Ejemplo n.º 9
0
        public async Task <ActionResult <Brand> > AddBrand(Brand brand)
        {
            try
            {
                if (brand == null)
                {
                    return(BadRequest());
                }
                else
                {
                    var createdBrand = await _brandRepository.AddBrand(brand);

                    return(createdBrand);
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error with posting data to the database"));
            }
        }
 public void AddBrand(string brandName)
 {
     _repository.AddBrand(brandName);
 }