public SubSubCategoryViewModel GetSubSubCategoryById(long id)
        {
            SubSubCategoryViewModel subcategory = new SubSubCategoryViewModel();

            try
            {
                subcategory = _db.SubSubCategories.Where(x => x.Id == id).Select(x => new SubSubCategoryViewModel()
                {
                    Id                  = x.Id,
                    Name                = x.Name,
                    Name_French         = x.Name_French,
                    Name_Hebrew         = x.Name_Hebrew,
                    Name_Russian        = x.Name_Russian,
                    Description         = x.Description,
                    Description_French  = x.Description_French,
                    Description_Hebrew  = x.Description_Hebrew,
                    Description_Russian = x.Description_Russian,
                    IsActive            = x.IsActive,
                    SubCategoryId       = x.SubCategory.Id,
                    SubCategoryName     = x.SubCategory.Name,
                    //HasPrice = x.SubCategory.Category.HasPrice == true
                    //   ? "yes" : "no",
                    Price       = x.Price,
                    ClientPrice = x.ClientPrice,
                    Picture     = x.Picture,
                    Icon        = x.Icon
                }).FirstOrDefault();
            }
            catch (Exception ex)
            {
            }
            return(subcategory);
        }
        public ActionResult AddSubSubCategory(long?id, int?pageNumber)
        {
            TempData["IndexPage"]  = pageNumber;
            TempData["ErrorMsg"]   = null;
            TempData["SuccessMsg"] = null;
            TempData["Title"]      = id == 0 || id == null ? Resource.add_sub_sub_service : Resource.edit_sub_sub_service;
            var subcategories = categoryService.GetSubCategoriesSelect();

            ViewBag.SubCategories = subcategories;
            if (id != null)
            {
                var subcategory = categoryService.GetSubSubCategoryById(id ?? 0);
                return(View(subcategory));
            }
            else
            {
                var model = new SubSubCategoryViewModel();
                if (subcategories.Count > 0)
                {
                    var catData = categoryService.GetCategoryById(Convert.ToInt64(subcategories[0].Value));
                    model.HasPrice = catData != null && catData.HasPrice == true
                        ? Resource.yes : Resource.no;
                }
                return(View(model));
            }
        }
Пример #3
0
 public ActionResult Create(SubSubCategoryViewModel subSubCategoryViewModel)
 {
     if (ModelState.IsValid)
     {
         SubSubCategoryServices.Create(subSubCategoryViewModel);
         return(RedirectToAction("Index"));
     }
     loadAll();
     return(View(subSubCategoryViewModel));
 }
Пример #4
0
 public ActionResult Edit(SubSubCategoryViewModel subSubCategoryViewModel)
 {
     if (ModelState.IsValid)
     {
         SubSubCategoryServices.Update(subSubCategoryViewModel);
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId    = new SelectList(CategoryServices.GetAll(), "CategoryId", "CategoryName", subSubCategoryViewModel.CategoryId);
     ViewBag.SubCategoryId = new SelectList(SubCategoryServices.GetAll(), "SubCategoryId", "SubCategoryName", subSubCategoryViewModel.SubCategoryId);
     return(View(subSubCategoryViewModel));
 }
        public void Create(SubSubCategoryViewModel SubSubCategoryViewModel)
        {
            var SubSubCategory = new SubSubCategory
            {
                SubSubCategoryName = SubSubCategoryViewModel.SubSubCategoryName,
                SubCategoryId      = SubSubCategoryViewModel.SubCategoryId,
                CategoryId         = SubSubCategoryViewModel.CategoryId
            };

            unitOfWork.SubSubCategoryRepository.Insert(SubSubCategory);
            unitOfWork.Save();
        }
Пример #6
0
        // GET: SubSubCategory/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SubSubCategoryViewModel subSubCategoryViewModel = SubSubCategoryServices.GetByID(id);

            if (subSubCategoryViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(subSubCategoryViewModel));
        }
        public bool AddUpdateSubSubCategory(SubSubCategoryViewModel model)
        {
            bool status = false;

            try
            {
                if (model.Id != 0)
                {
                    var subCatData = _db.SubSubCategories.Where(x => x.Id == model.Id).FirstOrDefault();
                    if (subCatData != null)
                    {
                        var validName = _db.SubSubCategories.Where(x => x.Name.ToLower().Trim() ==
                                                                   model.Name.ToLower().Trim() && x.Id != model.Id && x.SubCatId == model.SubCategoryId).FirstOrDefault();
                        if (validName != null)
                        {
                            message = Resource.sub_sub_service_name_already_exists;
                        }
                        else
                        {
                            subCatData.Name                = model.Name;
                            subCatData.Name_French         = model.Name_French;
                            subCatData.Name_Hebrew         = model.Name_Hebrew;
                            subCatData.Name_Russian        = model.Name_Russian;
                            subCatData.Description         = model.Description;
                            subCatData.Description_French  = model.Description_French;
                            subCatData.Description_Hebrew  = model.Description_Hebrew;
                            subCatData.Description_Russian = model.Description_Russian;
                            subCatData.Price               = model.Price;
                            subCatData.ClientPrice         = model.ClientPrice;
                            subCatData.SubCatId            = model.SubCategoryId;
                            subCatData.Picture             = !string.IsNullOrEmpty(model.Picture) ? model.Picture : subCatData.Picture;
                            subCatData.Icon                = !string.IsNullOrEmpty(model.Icon) ? model.Icon : subCatData.Icon;
                            subCatData.ModifiedDate        = DateTime.Now;
                            _db.SaveChanges();
                            status  = true;
                            message = Resource.sub_sub_service_update_success;
                            status  = true;
                        }
                    }
                    else
                    {
                        message = Resource.sub_sub_service_not_exists;
                    }
                }
                else
                {
                    var validName = _db.SubSubCategories.Where(x => x.Name.ToLower().Trim() ==
                                                               model.Name.ToLower().Trim() && x.SubCatId == model.SubCategoryId).FirstOrDefault();
                    if (validName != null)
                    {
                        message = Resource.sub_sub_service_name_already_exists;
                    }
                    else
                    {
                        SubSubCategory subsubcategory = new SubSubCategory();
                        subsubcategory.CreatedDate         = DateTime.Now;
                        subsubcategory.IsActive            = true;
                        subsubcategory.Price               = model.Price;
                        subsubcategory.ClientPrice         = model.ClientPrice;
                        subsubcategory.SubCatId            = model.SubCategoryId;
                        subsubcategory.Name                = model.Name;
                        subsubcategory.Name_French         = model.Name_French;
                        subsubcategory.Name_Hebrew         = model.Name_Hebrew;
                        subsubcategory.Name_Russian        = model.Name_Russian;
                        subsubcategory.Description         = model.Description;
                        subsubcategory.Description_French  = model.Description_French;
                        subsubcategory.Description_Hebrew  = model.Description_Hebrew;
                        subsubcategory.Description_Russian = model.Description_Russian;
                        subsubcategory.Picture             = model.Picture;
                        subsubcategory.Icon                = model.Icon;
                        _db.SubSubCategories.Add(subsubcategory);
                        _db.SaveChanges();

                        status  = true;
                        message = Resource.sub_sub_service_add_success;
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(status);
        }
        public ActionResult AddSubSubCategory(SubSubCategoryViewModel model, HttpPostedFileBase file,
                                              HttpPostedFileBase fileIcon)
        {
            var pageNumber = TempData["IndexPage"];

            TempData["Title"] = model.Id == 0 ? Resource.add_sub_sub_service : Resource.edit_sub_sub_service;
            if (ModelState.IsValid)
            {
                var date = DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss").Replace("-", "_");
                if (file != null)
                {
                    IList <string> AllowedFileExtensions = new List <string> {
                        ".jpg", ".png", ".jpeg", ".JPG", ".PNG", ".JPEG"
                    };
                    var ext = System.IO.Path.GetExtension(file.FileName);

                    var fileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + date + ext.ToLower();

                    //var fileName = System.IO.Path.GetFileNameWithoutExtension(file.FileName) + ext.ToLower();

                    if (!AllowedFileExtensions.Contains(ext))
                    {
                        ViewBag.ErrorMessage = Resource.file_extension_invalid;
                    }
                    ext = Path.GetExtension(file.FileName);
                    {
                        string path = "~/Images/SubSubCategory";
                        if (!Directory.Exists(Server.MapPath(path)))
                        {
                            Directory.CreateDirectory(Server.MapPath(path));
                        }

                        path = System.IO.Path.Combine(Server.MapPath(path),
                                                      System.IO.Path.GetFileName(fileName));
                        file.SaveAs(path);
                        model.Picture = fileName;
                    }
                }
                if (fileIcon != null)
                {
                    IList <string> AllowedFileExtensions = new List <string> {
                        ".jpg", ".png", ".jpeg", ".JPG", ".PNG", ".JPEG"
                    };
                    var ext = System.IO.Path.GetExtension(fileIcon.FileName);

                    var fileName = System.IO.Path.GetFileNameWithoutExtension(fileIcon.FileName) + ext.ToLower();

                    if (!AllowedFileExtensions.Contains(ext))
                    {
                        ViewBag.ErrorMessage = Resource.file_extension_invalid;
                    }
                    ext = Path.GetExtension(fileIcon.FileName);
                    {
                        string path = "~/Images/SubSubCategory";
                        if (!Directory.Exists(Server.MapPath(path)))
                        {
                            Directory.CreateDirectory(Server.MapPath(path));
                        }

                        path = System.IO.Path.Combine(Server.MapPath(path),
                                                      System.IO.Path.GetFileName(fileName));
                        fileIcon.SaveAs(path);
                        model.Icon = fileName;
                    }
                }
                var result = categoryService.AddUpdateSubSubCategory(model);
                if (result)
                {
                    TempData["SuccessMsg"] = categoryService.message;
                    return(RedirectToAction("SubSubCategoryList", "Category", new { pageNumber = pageNumber }));
                }
                else
                {
                    TempData["ErrorMsg"] = categoryService.message;
                }
            }
            ViewBag.SubCategories = categoryService.GetSubCategoriesSelect();
            return(View(model));
        }