Exemple #1
0
        public static ProductSubCategoryViewModel ToVm(this ProductSubCategory model, IConfiguration config, ProductSubCategoryViewModel vm = null)
        {
            if (vm == null)
            {
                vm = new ProductSubCategoryViewModel();
            }

            vm.Id          = model.Id;
            vm.Name        = model.Name;
            vm.Description = model.Description;
            if (!string.IsNullOrEmpty(model.Picture))
            {
                //vm.ImageURL = string.Format("{0}/{1}/{2}/{3}", config.GetSection("FileUploadUrl").Value, FolderNames.INSURANCE, model.Vehicle.Id, model.Attachment);
                var imagePath = string.Format(@"{0}{1}\{2}\{3}\{4}\{5}",
                                              config.GetSection("FileUploadPath").Value,
                                              FolderNames.PRODUCT_CATEGORY,
                                              model.ProductCategoryId,
                                              FolderNames.PRODUCT_SUB_CATEGORY,
                                              model.Id,
                                              model.Picture);
                if (File.Exists(imagePath))
                {
                    vm.Picture = "data:image/jpg;base64," + ImageHelper.getThumnialImage(imagePath);
                }
            }
            vm.Picture  = model.Picture;
            vm.IsActive = model.IsActive.Value;

            return(vm);
        }
Exemple #2
0
        // GET: Control/ProductSubCategories/Edit/5
        public async Task <IActionResult> Edit(int?id, bool status = true)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ProductSubCategoryViewModel model = new ProductSubCategoryViewModel
            {
                ProductSubCategory           = await _context.ProductSubCategories.FirstOrDefaultAsync(x => x.Id == id),
                ProductSubCategoryTranslates = _context.ProductSubCategoryTranslates.Include("Language").Where(x => x.ProductSubCategoryId == id).ToList()
            };

            if (model.ProductSubCategory == null)
            {
                return(NotFound());
            }
            if (HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest")
            {
                model.ProductSubCategory.Status = status;
                _context.SaveChanges();
                return(Json(new { res = true }));
            }
            ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategoryTranslates.Where(x => x.LanguageId == 2), "ProductCategoryId", "Name", model.ProductSubCategory.Id);
            return(View(model));
        }
Exemple #3
0
        public ActionResult Create(int categoryId)
        {
            var model = new ProductSubCategoryViewModel
            {
                ProductCategoryId = categoryId
            };

            return(View(model));
        }
 public JavaScriptResult Create(ProductSubCategoryViewModel productSubCategoryvm)
 {
     try
     {
         _productSubCategoryService.Add(Mapper.Map <ProductSubCategory>(productSubCategoryvm));
         return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/ProductSubCategory/?productCategoryId=" + productSubCategoryvm.ProductCategoryId}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','failure')"));
     }
 }
Exemple #5
0
        public async Task <IActionResult> Edit(int id, ProductSubCategoryViewModel model)
        {
            if (id != model.ProductSubCategory.Id)
            {
                return(NotFound());
            }
            if (model.ProductSubCategory.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.ProductSubCategory.Photo = fileManager.Upload(model.ProductSubCategory.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                foreach (var item in model.ProductSubCategoryTranslates)
                {
                    item.ProductSubCategoryId = id;
                    _context.ProductSubCategoryTranslates.Update(item);
                }
                await _context.SaveChangesAsync();

                try
                {
                    model.ProductSubCategory.ModifiedAt = DateTime.Now;
                    _context.ProductSubCategories.Update(model.ProductSubCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductSubCategoryExists(model.ProductSubCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
            return(View(model));
        }
Exemple #6
0
        public ActionResult Create(ProductSubCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var entity = _mapper.Map <ProductSubCategoryViewModel, ProductSubCategory>(model);

            _productSubCategoryService.Add(entity);

            TempData[TempDataMessageKey] = "Новая подкатегория была добавлена";

            return(RedirectToAction("Index", "Admin"));
        }
        public ProductSubCategoryViewModel GetProductSubCategoryById(long id)
        {
            var response = new ProductSubCategoryViewModel();

            var pCategory = _db.ProductSubCategories.FirstOrDefault(x => x.Id == id);

            response.Description       = pCategory.Description;
            response.Id                = pCategory.Id;
            response.IsActive          = pCategory.IsActive.Value;
            response.Name              = pCategory.Name;
            response.Picture           = pCategory.Picture;
            response.ProductCategoryId = pCategory.ProductCategoryId;

            return(response);
        }
Exemple #8
0
        public static ProductSubCategory ToModel(this ProductSubCategoryViewModel vm, ProductSubCategory model = null)
        {
            if (model == null)
            {
                model = new ProductSubCategory();
            }

            model.Id   = vm.Id;
            model.Name = vm.Name;
            model.ProductCategoryId = vm.ProductCategoryId;
            model.Description       = vm.Description;
            model.Picture           = vm.Picture;
            model.IsActive          = vm.IsActive;

            return(model);
        }
        public async Task <ResponseViewModel> SaveProductSubCategory(ProductSubCategoryViewModel vm, string userName)
        {
            var response = new ResponseViewModel();

            try
            {
                var category = _db.ProductSubCategories.FirstOrDefault(d => d.Id == vm.Id);

                if (category == null)
                {
                    category = new Model.ProductSubCategory()
                    {
                        Name              = vm.Name,
                        Description       = vm.Description,
                        IsActive          = true,
                        Picture           = vm.Picture,
                        ProductCategoryId = vm.ProductCategoryId
                    };

                    _db.ProductSubCategories.Add(category);
                    await _db.SaveChangesAsync();

                    response.IsSuccess = true;
                    response.Message   = "New Product sub category has been added.";
                }
                else
                {
                    category.Description       = vm.Description;
                    category.Name              = vm.Name;
                    category.Picture           = vm.Picture;
                    category.ProductCategoryId = vm.ProductCategoryId;

                    _db.ProductSubCategories.Update(category);
                    await _db.SaveChangesAsync();

                    response.IsSuccess = true;
                    response.Message   = "Product sub category has been updated.";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = true;
                response.Message   = "Error has been occured while saving the data. Please try again.";
            }

            return(response);
        }
Exemple #10
0
        // GET: Control/ProductSubCategories/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ProductSubCategoryViewModel model = new ProductSubCategoryViewModel
            {
                ProductSubCategory           = await _context.ProductSubCategories.Include("ProductCategory.ProductCategoryTranslate").FirstOrDefaultAsync(x => x.Id == id),
                ProductSubCategoryTranslates = _context.ProductSubCategoryTranslates.Include("Language").Where(x => x.ProductSubCategoryId == id).ToList()
            };

            if (model.ProductSubCategory == null)
            {
                return(NotFound());
            }

            return(View(model));
        }
Exemple #11
0
        public async Task <IActionResult> Create(ProductSubCategoryViewModel model)
        {
            if (_context.ProductSubCategoryTranslates.Any(x => x.Name.ToLower() == model.ProductSubCategoryTranslates[1].Name.ToLower()))
            {
                ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
                ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
                TempData["Error"]             = "Bu adda Alt kateqoriya mövcuddur!";
                return(View(model));
            }
            if (model.ProductSubCategory.PhotoUpload != null)
            {
                try
                {
                    FileManager fileManager = new FileManager(_webHostEnvironment);
                    model.ProductSubCategory.Photo = fileManager.Upload(model.ProductSubCategory.PhotoUpload);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PhotoUpload", e.Message);
                }
            }
            if (ModelState.IsValid)
            {
                model.ProductSubCategory.CreatedAt  = DateTime.Now;
                model.ProductSubCategory.ModifiedAt = DateTime.Now;
                model.ProductSubCategory.Status     = true;
                _context.Add(model.ProductSubCategory);
                await _context.SaveChangesAsync();

                foreach (var productSubCategory in model.ProductSubCategoryTranslates)
                {
                    productSubCategory.ProductSubCategoryId = _context.ProductSubCategories.FirstOrDefault(x => x.Photo == model.ProductSubCategory.Photo && x.CreatedAt == model.ProductSubCategory.CreatedAt).Id;
                    _context.Add(productSubCategory);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Alt kateqoriya yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdminManagerId"]    = new SelectList(_context.AdminManagers, "Id", "Email", model.ProductSubCategory.AdminManagerId);
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "Id", "Id", model.ProductSubCategory.ProductCategoryId);
            return(View(model));
        }
Exemple #12
0
        public ActionResult Update(ProductSubCategoryViewModel model)
        {
            var entityExists = _productSubCategoryService.CheckIfExists(model.Id);

            if (!entityExists)
            {
                TempData[TempDataErrorKey] = "Подкатегория с таким id не сушествует";

                return(RedirectToAction("Index", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var entity = _mapper.Map <ProductSubCategoryViewModel, ProductSubCategory>(model);

            _productSubCategoryService.Update(entity);

            TempData[TempDataMessageKey] = "Подкатегория была обновлена";

            return(RedirectToAction("Index", "Admin"));
        }