Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(BrandVm data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var brand = await _db.Brands.FindAsync(data.BrandId);

                        if (brand == null)
                        {
                            ModelState.AddModelError(ErrorMessage.DataNotFound, ErrorMessage.DataNotFound);
                        }
                        else
                        {
                            brand.Name             = data.Name;
                            brand.UpdatedDate      = DateTime.UtcNow;
                            brand.UpdatedBy        = StaticValues.UserId;//Static UserId
                            _db.Entry(brand).State = EntityState.Modified;
                            await _db.SaveChangesAsync();

                            TempData["Success"] = SuccessMessage.Updated;
                            return(RedirectToAction("Index", "Brand", new { area = "ControlPanel", id = data.BrandId }));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(data.BrandId)));
        }
Ejemplo n.º 2
0
        public void AddBrandToDb(BrandVm bind)
        {
            var brand = Mapper.Map <BrandVm, Brand>(bind);

            context.Brands.Add(brand);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Add(BrandVm data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var brand = new Brand
                        {
                            Name        = data.Name,
                            CreatedDate = DateTime.UtcNow,
                            CreatedBy   = User.Identity.GetUserId()
                        };

                        _db.Entry(brand).State = EntityState.Added;
                        await _db.SaveChangesAsync();
                    }

                    TempData["Success"] = SuccessMessage.Added;
                    return(RedirectToAction("Index", "Brand", new { area = "ControlPanel" }));
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(0)));
        }
Ejemplo n.º 4
0
 public ActionResult Edit(BrandVm bind)
 {
     if (ModelState.IsValid)
     {
         service.EditBrand(bind);
         return(RedirectToAction("Index"));
     }
     return(View(bind));
 }
Ejemplo n.º 5
0
 public ActionResult Add(BrandVm bind)
 {
     if (ModelState.IsValid)
     {
         service.AddBrandToDb(bind);
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 6
0
        public void EditBrand(BrandVm bind)
        {
            var brand = context.Brands.Find(bind.Id);

            brand = Mapper.Map <BrandVm, Brand>(bind, brand);

            context.Entry(brand).State = EntityState.Modified;
            context.SaveChanges();
        }
Ejemplo n.º 7
0
        public void AddBrand(BrandVm brand)
        {
            var _brand = new Brand
            {
                Name = brand.Name
            };

            _context.Brands.Add(_brand);
            _context.SaveChanges();
        }
Ejemplo n.º 8
0
        public async Task <BrandVm> GetById(string id)
        {
            var brand = await _context.productBrand.FindAsync(id);

            var brandViewModel = new BrandVm()
            {
                IdBrand = brand.idBrand,
                Name    = brand.idBrand,
                Details = brand.brandDetail,
            };

            return(brandViewModel);
        }
        // GET: Purchase/Create
        public ActionResult Create()
        {
            List <BrandVm> BrandList = new List <BrandVm>();
            var            brands    = db.Brands.ToList();

            foreach (var item in brands)
            {
                BrandVm obj = new BrandVm();
                obj.BrandID   = item.BrandID;
                obj.BrandName = item.BrandName;
                BrandList.Add(obj);
            }

            return(View(BrandList));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <BrandVm> > GetBrand(int id)
        {
            var brand = await _context.Brands.FindAsync(id);

            if (brand == null)
            {
                return(NotFound());
            }

            var brandVm = new BrandVm
            {
                Id   = brand.Id,
                Name = brand.Name
            };

            return(brandVm);
        }
Ejemplo n.º 11
0
        public async Task <BrandVm> GetBrandById(int id)
        {
            var brand = await _context.Brands.FindAsync(id);

            if (brand == null)
            {
                return(new BrandVm());
            }

            var brandVm = new BrandVm
            {
                BrandId = brand.BrandId,
                Name    = brand.Name
            };

            return(brandVm);
        }
Ejemplo n.º 12
0
        public async Task <BrandVm> PostBrand(BrandCreateRequest request)
        {
            var brand = new EcommerceShop.Application.Models.Brand
            {
                Name = request.Name
            };

            _context.Brands.Add(brand);
            await _context.SaveChangesAsync();

            var brandVm = new BrandVm
            {
                BrandId = brand.BrandId,
                Name    = brand.Name
            };

            return(brandVm);
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <BrandVm> > GetBrand(short id)
        {
            var brand = await _context.Brands.FindAsync(id);

            var brandvm = new BrandVm
            {
                ID     = brand.ID,
                Name   = brand.Name,
                Status = brand.Status
            };

            if (brand == null)
            {
                return(NotFound());
            }

            return(brandvm);
        }
Ejemplo n.º 14
0
        public async Task <ActionResult <BrandVm> > Get(long id)
        {
            var brand = await _brandRepository.Query().FirstOrDefaultAsync(x => x.Id == id);

            if (brand == null)
            {
                return(NotFound());
            }

            var model = new BrandVm
            {
                Id          = brand.Id,
                Name        = brand.Name,
                Slug        = brand.Slug,
                IsPublished = brand.IsPublished
            };

            return(model);
        }
Ejemplo n.º 15
0
        public ActionResult Brand(BrandVm model)
        {
            if (ModelState.IsValid)
            {
                Entity.EntityModels.Brand brand = Mapper.Map <Entity.EntityModels.Brand>(model);
                if (brand.Id == 0)
                {
                    ViewBag.message = brandManager.Save(brand);
                }
                else
                {
                    ViewBag.message = brandManager.Update(brand);
                }
                model = new BrandVm();
                ModelState.Clear();
            }
            List <Common> brands = commonManager.GetAllBrand();

            ViewBag.Brand = brands;
            return(View(model));
        }
Ejemplo n.º 16
0
        public ActionResult AddBrandView(string name)
        {
            var allShoesVm = new ShoeListViewModel
            {
                Shoes = _shoesService.GetAllShoes()
            };
            var allBrandsVM = _brandServices.GetAllBrands();


            dynamic myModel = new ExpandoObject();

            myModel.AllShoes = allShoesVm.Shoes;
            myModel.Brand    = allBrandsVM;

            try
            {
                if (ModelState.IsValid)
                {
                    var brand = new BrandVm()
                    {
                        Name = name,
                    };

                    if (!string.IsNullOrWhiteSpace(brand.Name))
                    {
                        _brandServices.AddBrand(brand);
                    }
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "Some Error";
            }

            return(View("Index", myModel));
        }
Ejemplo n.º 17
0
 public IActionResult AddBrand([FromBody] BrandVm brand)
 {
     _brandService.AddBrand(brand);
     return(Ok());
 }