Пример #1
0
        public ActionResult AddSubCategories(SubCategory obj)
        {
            SubCategory subobj   = new SubCategory();
            string      _imgname = string.Empty;
            var         imgPath2 = string.Empty;

            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var pic = System.Web.HttpContext.Current.Request.Files["file"];
                if (pic.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(pic.FileName);
                    var _ext     = Path.GetExtension(pic.FileName);
                    _imgname = Guid.NewGuid().ToString();
                    var _comPath = String.Empty;
                    switch (obj.Category)
                    {
                    case 1:
                        _comPath = Server.MapPath("~/Images/IronWork/") + _imgname + _ext;
                        imgPath2 = "/Images/IronWork/" + _imgname + _ext;
                        break;

                    case 2:
                        _comPath = Server.MapPath("~/Images/Landscape/") + _imgname + _ext;
                        imgPath2 = "/Images/Landscape/" + _imgname + _ext;
                        break;

                    case 3:
                        _comPath = Server.MapPath("~/Images/Masonary/") + _imgname + _ext;
                        imgPath2 = "/Images/Masonary/" + _imgname + _ext;
                        break;

                    case 4:
                        _comPath = Server.MapPath("~/Images/Construction/") + _imgname + _ext;
                        imgPath2 = "/Images/Construction/" + _imgname + _ext;
                        break;

                    case 5:
                        _comPath = Server.MapPath("~/Images/Kitchens/") + _imgname + _ext;
                        imgPath2 = "/Images/Kitchens/" + _imgname + _ext;
                        break;

                    case 6:
                        _comPath = Server.MapPath("~/Images/DriveWays/") + _imgname + _ext;
                        imgPath2 = "/Images/DriveWays/" + _imgname + _ext;
                        break;

                    default:
                        Console.WriteLine("Invalid grade");
                        break;
                    }
                    var path = _comPath;
                    pic.SaveAs(path);

                    if (obj.SubCategoryId == 0)
                    {
                        subobj.AddSubcategory(obj, imgPath2);
                        return(Json("SubCategory Added Succesfully", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        subobj.UpdateSubCategory(obj, imgPath2);
                        return(Json("Subcategory Updated Succesfully", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            subobj.UpdateSubCategory(obj, imgPath2);
            return(Json("SubCategory Updated Succesfully", JsonRequestBehavior.AllowGet));
        }