Пример #1
0
        //create brand
        public async Task <BrandViewsModels> Create(BrandViewsModels addBrand)
        {
            var brand = new Brand()
            {
                BrandName = addBrand.BrandName
            };

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

            return(addBrand);
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, BrandViewsModels editBrand)
        {
            if (ModelState.IsValid)
            {
                if (id == editBrand.Id)
                {
                    await _brandService.EditBrand(id, editBrand);

                    TempData["EditSuccessfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly").ToString();
                    return(RedirectToAction("Index"));
                }
            }
            ViewData["EditFailure"] = _brandLocalizer.GetLocalizedString("err_EditFailure");
            return(View());
        }
Пример #3
0
        public async Task <IActionResult> Create(BrandViewsModels brand)
        {
            if (ModelState.IsValid)
            {
                var addBrand = await _brandService.Create(brand);

                if (addBrand != null)
                {
                    TempData["AddSuccessfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly").ToString();
                    return(RedirectToAction("Index", addBrand));
                }
            }
            ViewData["AddFailure"] = _brandLocalizer.GetLocalizedString("err_AddFailure");
            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Edit(BrandViewsModels editBrand)
        {
            if (ModelState.IsValid)
            {
                var brand = await _brandService.EditBrandAsync(editBrand);

                if (brand)
                {
                    TempData["Successfuly"] = _localizer.GetLocalizedString("msg_EditSuccessfuly").ToString();
                    return(RedirectToAction("Index"));
                }
                TempData["EditFailure"] = _localizer.GetLocalizedString("err_EditFailure").ToString();
                return(View(editBrand));
            }
            return(View(editBrand));
        }
Пример #5
0
        //post edit band = try catch
        public async Task <bool> EditBrandAsync(BrandViewsModels editBrand)
        {
            try
            {
                var brand = await _context.Brands.FindAsync(editBrand.Id);

                brand.BrandName = editBrand.BrandName;
                _context.Brands.Update(brand);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #6
0
        /// <summary>
        /// post brand edit service
        /// </summary>
        /// <param name="editBrand">BrandViewsModels</param>
        /// <returns>true || flase</returns>
        public async Task <bool> EditBrandAsync(BrandViewsModels editBrand)
        {
            try
            {
                var brand = await _context.Brands.FindAsync(editBrand.Id);

                brand.BrandName = editBrand.BrandName;
                _context.Brands.Update(brand);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Edit Brand Async Error: {0}", e.Message);
                return(false);
            }
        }
Пример #7
0
        public async Task <IActionResult> Create(BrandViewsModels brand)
        {
            if (ModelState.IsValid)
            {
                var addBrand = await _brandService.AddBrandAsync(brand);

                if (addBrand)
                {
                    TempData["Successfuly"] = _localizer.GetLocalizedString("msg_AddSuccessfuly").ToString();
                    return(RedirectToAction("Index"));
                }
                Log.Error("Add user error ");
                ViewData["EditFailure"] = _localizer.GetLocalizedString("err_AddFailure");
                return(View(brand));
            }
            Log.Error("Add user error ");
            return(View(brand));
        }
Пример #8
0
        /// <summary>
        /// add brand service
        /// </summary>
        /// <param name="addBrand">BrandViewsModels</param>
        /// <returns>true || false</returns>
        public async Task <bool> AddBrandAsync(BrandViewsModels addBrand)
        {
            try
            {
                var brand = new Brand()
                {
                    BrandName = addBrand.BrandName
                };
                _context.Brands.Add(brand);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("Add Brand Async Error: {0}", e.Message);
                return(false);
            }
        }
Пример #9
0
        //post edit band = try catch
        public async Task <BrandViewsModels> EditBrand(int?id, BrandViewsModels editBrand)
        {
            try
            {
                var brand = _context.Brands.Find(id);

                brand.BrandName = editBrand.BrandName;

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

                return(editBrand);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Пример #10
0
        //create brand
        public async Task <bool> AddBrandAsync(BrandViewsModels addBrand)
        {
            try
            {
                var brand = new Brand()
                {
                    BrandName = addBrand.BrandName
                };

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

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }