public IActionResult CreateBrand([FromBody] Brand brand)
        {
            try
            {
                if (brand.IsEntityNull())
                {
                    return(BadRequest("Brand object is null"));
                }

                if (!brand.IsEntityEmpty())
                {
                    return(BadRequest("For create, the Id must be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                _brandService.CreateBrand(brand);
                _brandService.Save();

                return(CreatedAtRoute("BrandById", new { id = brand.Id.Value }, brand));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/brand/CreateBrand", brand);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Ejemplo n.º 2
0
 public IActionResult AddOrEdit(int id, BrandDto brand)
 {
     if (ModelState.IsValid)
     {
         if (id == 0)
         {
             brandService.CreateBrand(brand);
         }
         else
         {
             try
             {
                 brandService.UpdateBrand(brand);
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!brandService.BrandExists(brand.Id))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         var brands = brandService.GetAll();
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", brands) }));
     }
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", brand) }));
 }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Post(BrandCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var advertiser = await _advertiserService.GetAdvertiser(model.AdvertiserUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

            if (advertiser == null)
            {
                return(BadRequest("The specified advertiser was not found."));
            }

            var productCategory = await _productCategoryService.GetProductCategory(model.ProductCategoryId.GetValueOrDefault(0)).ConfigureAwait(false);

            if (productCategory == null)
            {
                return(BadRequest("The specified product category was not found."));
            }

            var brand = _mapping.Map <AdvertiserProduct>(model);
            await _brandService.CreateBrand(brand).ConfigureAwait(false);

            brand = await _brandService.GetBrand(brand.AdvertiserProductUuid).ConfigureAwait(false);

            var brandViewModel = _mapping.Map <BrandViewModel>(brand);

            return(CreatedAtRoute("Brands.GetById", new { Id = brandViewModel.BrandUuid }, brandViewModel));
        }
Ejemplo n.º 4
0
        public IActionResult CreateBrand(BrandViewModel brandViewModel)
        {
            Brand brand = _brandService.CreateBrand(brandViewModel);

            return(new JsonResult(brand)
            {
                StatusCode = StatusCodes.Status200OK
            });
        }
Ejemplo n.º 5
0
 public ActionResult <Brand> Post([FromBody] Brand brand)
 {
     try
     {
         return(Ok(_brandService.CreateBrand(brand)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public async Task <IActionResult> Post([FromBody] BrandCreateModel brandCreateModel)
        {
            if (await _brandService.BrandExist(brandCreateModel.Title))
            {
                return(Conflict("Such brand already exists"));
            }
            BrandDto brandDto        = _mapper.Map <BrandDto>(brandCreateModel);
            BrandDto createdBrandDto = await _brandService.CreateBrand(brandDto);

            BrandWebModel brandModel = _mapper.Map <BrandWebModel>(createdBrandDto);

            return(CreatedAtAction(nameof(Get), new { id = brandModel.BrandId }, brandModel));
        }
        public IActionResult Save(BrandRequestDTO request)
        {
            if (request.Id > 0)
            {
                _service.UpdateBrand(request);
            }
            else
            {
                _service.CreateBrand(request);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([FromForm] BrandCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var idBrand = await _brandService.CreateBrand(request);


            var brand = await _brandService.GetById(idBrand);

            return(CreatedAtAction(nameof(GetById), new { id = idBrand }, brand));
        }
Ejemplo n.º 9
0
 public ActionResult Create(BrandViewModel collection, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file.ContentLength > 0)
         {
             var fileName = Path.GetFileName(file.FileName);
             var path     = Path.Combine(("/Content/img"), fileName);
             var SavePath = Path.Combine(Server.MapPath("~/Content/img"), fileName);
             collection.BrandImage = path;
             file.SaveAs(SavePath);
             collection.BrandID = Convert.ToInt16(Session["BrandID"]);
             brandServices.CreateBrand(collection);
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 10
0
        public async Task <ActionResult <BrandDto> > CreateBrand([FromBody] CreateBrandRequestModel requestModel)
        {
            BrandDto responseModel = await brandService.CreateBrand(
                new CreateBrandDto
            {
                Name        = requestModel.Name,
                Description = requestModel.Description,
                Url         = requestModel.Description,
                Image       = await imageWriter.UploadImage(requestModel.Image)
            });

            if (responseModel == null)
            {
                return(InvalidRequest());
            }

            return(CreatedAtAction(nameof(CreateBrand), new { id = responseModel.Id }, responseModel));
        }
Ejemplo n.º 11
0
        public ActionResult <Brand> CreateBrand([FromBody] Brand brand)
        {
            try
            {
                Brand addedBrand = BrandService.CreateBrand(brand);

                if (addedBrand == null)
                {
                    return(StatusCode(500, "Error saving brand to Database"));
                }

                return(Created("", addedBrand));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <BrandResource> > CreateBrand([FromBody] SaveBrandResource saveBrandResource)
        {
            var validator        = new SaveBrandResourceValidator();
            var validationResult = await validator.ValidateAsync(saveBrandResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors)); // this needs refining, but for demo it is ok
            }
            var brandToCreate = _mapper.Map <SaveBrandResource, Brand>(saveBrandResource);

            var newBrand = await _brandService.CreateBrand(brandToCreate);

            var brand = await _brandService.GetBrandById(newBrand.BrandId);

            var brandResource = _mapper.Map <Brand, BrandResource>(brand);

            return(Ok(brandResource));
        }
        public async Task <IActionResult> CreateBrand([FromBody] CreateBrandResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var brandInput = _mapper.Map <CreateBrandResource, Brand>(resource);
                brandInput.AddedBy = _admin.Fullname;
                var brand = await _brandService.CreateBrand(brandInput);

                return(Ok(new { message = "Brend yaradıldı" }));
            }
            catch (HttpException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 14
0
 public ActionResult Edit(BrandSinglePageViewModel model)
 {
     if (model.BrandViewModel.BrandId == 0)
     {
         CreateBrandRequest  request  = new CreateBrandRequest();
         CreateBrandResponse response = new CreateBrandResponse();
         request.Name = model.BrandViewModel.Name;
         response     = brandService.CreateBrand(request);
         if (response.Success)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             model.Success      = false;
             model.ErrorMessage = response.Message;
             return(View(model));
         }
     }
     else
     {
         UpdateBrandRequest  request  = new UpdateBrandRequest();
         UpdateBrandResponse response = new UpdateBrandResponse();
         request.BrandId = model.BrandViewModel.BrandId;
         request.Name    = model.BrandViewModel.Name;
         response        = brandService.UpdateBrand(request);
         if (response.Success)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             model.Success      = false;
             model.ErrorMessage = response.Message;
             return(View(model));
         }
     }
 }
Ejemplo n.º 15
0
 public IActionResult CreateBrand(BrandCreateModel model)
 {
     _brandService.CreateBrand(model);
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 16
0
        public void InitData()
        {
            #region BeerTypes
            BeerType hvedeøl = new BeerType {
                ID = 1, TypeName = "Hvedeøl"
            };
            BeerType steam = new BeerType {
                ID = 2, TypeName = "Steam"
            };
            BeerType stout = new BeerType {
                ID = 3, TypeName = "Stout"
            };
            BeerType IPA = new BeerType {
                ID = 4, TypeName = "IPA"
            };
            BeerType pilsner = new BeerType {
                ID = 5, TypeName = "Pilsner"
            };
            BeerType saison = new BeerType {
                ID = 6, TypeName = "Saison"
            };

            BeerTypeService.CreateType(hvedeøl);
            BeerTypeService.CreateType(steam);
            BeerTypeService.CreateType(stout);
            BeerTypeService.CreateType(IPA);
            BeerTypeService.CreateType(pilsner);
            BeerTypeService.CreateType(saison);
            #endregion

            #region Brands
            Brand ølværket = new Brand {
                ID = 1, BrandName = "Ølværket"
            };
            Brand esbjergBryhus = new Brand {
                ID = 2, BrandName = "Esbjerg Bryghus"
            };
            Brand carlsberg = new Brand {
                ID = 3, BrandName = "Carlsberg"
            };

            BrandService.CreateBrand(ølværket);
            BrandService.CreateBrand(esbjergBryhus);
            BrandService.CreateBrand(carlsberg);
            #endregion

            #region Beers
            Beer borebisse = new Beer
            {
                Name        = "Borebisse",
                Description = "Noter af lakrids, kaffe og karamel.",
                Price       = 49.95,
                Percentage  = 8.5,
                IBU         = 60,
                EBC         = 70,
                Stock       = 5,
                ImageURL    = "https://firebasestorage.googleapis.com/v0/b/eb-sdm3.appspot.com/o/XL%20BOREBISSE.png?alt=media&token=e810dddf-e099-4ea5-ab4d-af5067eba37b",
                Type        = stout,
                Brand       = ølværket
            };

            Beer cargo = new Beer
            {
                Name        = "Cargo",
                Description = "Noter af Citrus",
                Price       = 49.95,
                Percentage  = 5.4,
                IBU         = 60,
                EBC         = 26,
                Stock       = 3,
                ImageURL    = "https://firebasestorage.googleapis.com/v0/b/eb-sdm3.appspot.com/o/XL%20CARGO.png?alt=media&token=8b5a4933-7331-401f-b906-0590e45ae20c",
                Type        = steam,
                Brand       = ølværket
            };

            Beer witch = new Beer
            {
                Name        = "Saison of the Witch",
                Description = "Noter af Appelsin og Grape",
                Price       = 49.95,
                Percentage  = 7.5,
                IBU         = 60,
                EBC         = 26,
                Stock       = 99,
                ImageURL    = "https://firebasestorage.googleapis.com/v0/b/eb-sdm3.appspot.com/o/258701189.png?alt=media&token=988b3f15-f5db-424f-bc3e-1ca6a497acf6",
                Type        = saison,
                Brand       = ølværket
            };

            Beer witchGinger = new Beer
            {
                Name        = "Saison of the Witch Ginger",
                Description = "Noter af Appelsin, Grape og Ingefær",
                Price       = 49.95,
                Percentage  = 7.5,
                IBU         = 60,
                EBC         = 26,
                Stock       = 10,
                ImageURL    = "https://firebasestorage.googleapis.com/v0/b/eb-sdm3.appspot.com/o/149572519.png?alt=media&token=d28f0523-22c5-4ade-9412-d296ce964986",
                Type        = saison,
                Brand       = ølværket
            };

            BeerService.CreateBeer(borebisse);
            BeerService.CreateBeer(cargo);
            BeerService.CreateBeer(witch);
            BeerService.CreateBeer(witchGinger);
            #endregion

            #region Users
            UserService.AddUser(UserService.CreateUser("SeglerHans", "password", "Admin"));
            UserService.AddUser(UserService.CreateUser("Kutterjørgen", "lasagne28", "User"));
            #endregion
        }
Ejemplo n.º 17
0
 public void Post([FromBody] Brand brand)
 {
     _brandService.CreateBrand(brand);
 }