public ActionResult AddOrEdit(Promotions promo)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (promo.Id == 0)
                    {
                        db.Promotion.Add(promo);
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Entry(promo).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public ActionResult AddOrEdit(Products prod)
        {
            try
            {
                if (prod.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(prod.ImageUpload.FileName);
                    string extension = Path.GetExtension(prod.ImageUpload.FileName);
                    fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    prod.ImagePath = "~/AppFiles/Images/" + fileName;
                    prod.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }
                if (prod.ImageUpload1 != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(prod.ImageUpload1.FileName);
                    string extension = Path.GetExtension(prod.ImageUpload1.FileName);
                    fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    prod.InnerBannerImage = "/AppFiles/Images/" + fileName;
                    prod.ImageUpload1.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }
                if (prod.CatalogueUplaoder != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(prod.CatalogueUplaoder.FileName);
                    string extension = Path.GetExtension(prod.CatalogueUplaoder.FileName);
                    fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    prod.Catalogue = "/AppFiles/docs/" + fileName;
                    prod.CatalogueUplaoder.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/docs/"), fileName));
                }
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (prod.Id == 0)
                    {
                        prod.Description = prod.Description == null ? " " : prod.Description;
                        db.Product.Add(prod);
                        db.SaveChanges();
                    }
                    else
                    {
                        prod.Description     = prod.Description == null ? " " : prod.Description;
                        db.Entry(prod).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAllProducts()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    var user = db.User.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = model.NewPassword;
                        user.ResetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult Register(Users userModel)
        {
            using (GerminmedContext db = new GerminmedContext())
            {
                userModel.IsAdmin = false;

                userModel.ActivationCode  = Guid.NewGuid().ToString();
                userModel.IsEmailVerified = false;
                userModel.IsActive        = false;
                if (db.User.Any(x => x.UserName == userModel.UserName))
                {
                    ViewBag.DuplicateMessage = "Username already exist.";
                    return(View("Register", userModel));
                }


                db.User.Add(userModel);
                db.SaveChanges();

                SendVerificationLinkEmail(userModel.Email, userModel.ActivationCode.ToString(), "VerifyAccount");
                ViewBag.SuccessMessage = "Germin MED Welcome you to Our online shopping. Email verification link " +
                                         " has been sent to your email :" + userModel.Email;
            }
            ModelState.Clear();
            // ViewBag.SuccessMessage = "Registration Successful.";
            return(View("Success"));
        }
Exemplo n.º 5
0
        public ActionResult ChangePassword(UserViewModel usr)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    var currentItem = db.User.Where(b => b.Id == usr.Id).FirstOrDefault <Users>();
                    if (currentItem.Password == usr.OldPassword)
                    {
                        currentItem.Password = usr.Password;
                        //  currentItem.OldPassword = usr.OldPassword;
                        currentItem.ConfirmPassword = usr.ConfirmPassword;
                        db.Entry(currentItem).State = EntityState.Modified;
                        db.SaveChanges();

                        return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ChangePassword", model: usr), message = "Password changed Successfully" }, behavior: JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Wrong Old password" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 6
0
        public ActionResult Approve(int Id)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;
                    Users usr = db.User.Where(x => x.Id == Id).FirstOrDefault <Users>();



                    if (usr.IsActive == false)
                    {
                        usr.IsActive = true;
                    }

                    //
                    //entities.Entry(user).Property(u => u.LastActivity).IsModified = true;
                    //entities.SaveChanges();

                    db.User.Attach(usr);
                    db.Entry(usr).Property(x => x.IsActive).IsModified = true;
                    db.SaveChanges();
                    SendVerificationLinkEmail(usr.Email, "", "Approve");
                }

                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAllRegisteredUser", model: GetAllRegisteredUser()), message = "Updated Successfully" }, behavior: JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 7
0
        public ActionResult Delete(int Id)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    Products prod = db.Product.Where(x => x.Id == Id).FirstOrDefault <Products>();

                    string fullPath = Request.MapPath(prod.ImagePath);
                    if (prod.ImagePath != "~/AppFiles/Images/Default.png")
                    {
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }
                    }
                    if (prod.Catalogue != null)
                    {
                        string fullPathCatalog = Request.MapPath(prod.Catalogue);
                        if (System.IO.File.Exists(fullPathCatalog))
                        {
                            System.IO.File.Delete(fullPathCatalog);
                        }
                    }

                    db.Product.Remove(prod);
                    db.SaveChanges();
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAllProducts()), message = "Deleted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 8
0
 public ActionResult DeleteImage(int Id, int productid)
 {
     try
     {
         using (GerminmedContext db = new GerminmedContext())
         {
             ProductImage img      = db.ProductImage.Where(x => x.Id == Id).FirstOrDefault <ProductImage>();
             string       fullPath = Request.MapPath(img.ImageUrl);
             if (img.ImageUrl != "~/AppFiles/Images/Default.png")
             {
                 if (System.IO.File.Exists(fullPath))
                 {
                     System.IO.File.Delete(fullPath);
                 }
             }
             db.ProductImage.Remove(img);
             db.SaveChanges();
         }
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewImagesByProduct", GetAllImagesByProduct(productid)), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 9
0
        public ActionResult OrederConfirm(UserViewModel uvm)
        {
            if (Session["cart"] != null && Session["UserId"] != null)
            {
                string       firstName         = uvm.FirstName;
                string       userName          = Session["userName"].ToString();
                string       phone             = uvm.Phone;
                string       cartTableForEmail = "";
                string       ToEmail           = uvm.Email;
                List <Cart>  cart      = (List <Cart>)Session["cart"];
                List <Order> orderList = new List <Order>();

                foreach (var item in cart)
                {
                    Order orderModel = new Order();
                    orderModel.ProductId = item.Product.Id;
                    orderModel.UserId    = (int)Session["UserId"];
                    orderModel.Qty       = item.Quantity;
                    orderList.Add(orderModel);
                    cartTableForEmail = cartTableForEmail + "<tr><td>" + item.Product.ProductName + "</td><td>" + item.Quantity + "</td><td>" + item.Product.Price + "</td></tr>";
                }
                using (GerminmedContext db = new GerminmedContext())
                {
                    db.Orders.AddRange(orderList);
                    db.SaveChanges();
                }
                SendEmail(firstName, userName, phone, cartTableForEmail);
                SendEmail(firstName, userName, phone, cartTableForEmail, ToEmail);
            }
            Session["cart"] = null;
            return(View());
        }
Exemplo n.º 10
0
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (GerminmedContext db = new GerminmedContext())
            {
                var account = db.User.Where(a => a.Email == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "Reset password link has been sent to your email id.";
                }
                else
                {
                    message = "Account not found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
 public ActionResult Delete(int Id)
 {
     try
     {
         using (GerminmedContext db = new GerminmedContext())
         {
             NewsLetter news     = db.NewsLetters.Where(x => x.Id == Id).FirstOrDefault <NewsLetter>();
             string     fullPath = Request.MapPath(news.ImageUrl);
             if (news.ImageUrl != "~/AppFiles/Images/Default.png")
             {
                 if (System.IO.File.Exists(fullPath))
                 {
                     System.IO.File.Delete(fullPath);
                 }
             }
             db.NewsLetters.Remove(news);
             db.SaveChanges();
         }
         return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Deleted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult AddOrEdit(NewsLetter news)
        {
            try
            {
                HttpPostedFileBase attach   = null;
                string             fileName = "";
                using (GerminmedContext db = new GerminmedContext())
                {
                    news.UserList = db.User.Where(x => x.UserTypeId == 1).ToList();
                    if (news.Id == 0)
                    {
                        if (news.ImageUpload != null)
                        {
                            attach   = news.ImageUpload;
                            fileName = Path.GetFileNameWithoutExtension(news.ImageUpload.FileName);
                            string extension = Path.GetExtension(news.ImageUpload.FileName);
                            fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                            news.ImageUrl = "~/AppFiles/Images/" + fileName;
                            news.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                        }

                        sendEmail(news.Subject, news.Message, news.Recipients, attach, fileName);

                        db.NewsLetters.Add(news);
                        db.SaveChanges();
                    }
                    else
                    {
                        var currentItem = db.NewsLetters.Where(b => b.Id == news.Id).FirstOrDefault <NewsLetter>();
                        currentItem.Message    = news.Message;
                        currentItem.Message    = news.Message;
                        currentItem.Recipients = news.Recipients;
                        sendEmail(news.Subject, news.Message, news.Recipients, attach, fileName);

                        db.Entry(currentItem).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (DataException ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 13
0
        public ActionResult AddImage(ProductImage img)
        {
            try
            {
                if (Session["ProductId"] != null)
                {
                    img.ProductId = (int)Session["ProductId"];
                }
                if (img.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(img.ImageUpload.FileName);
                    string extension = Path.GetExtension(img.ImageUpload.FileName);
                    fileName     = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    img.ImageUrl = "~/AppFiles/Images/" + fileName;
                    //img.ProductId = img.txtProductId;
                    img.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                    //   ResizeSettings resizeSetting = new ResizeSettings(560,305,FitMode.Max,"png");
                    //{
                    //    Width = 560,
                    //    Height = 305,
                    //    Format = "png"
                    //};
                    //  ImageBuilder.Current.Build(Path.Combine(Server.MapPath("~/AppFiles/Images/"),fileName), Path.Combine(Server.MapPath("~/AppFiles/Images/"),fileName), resizeSetting);
                }
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (img.Id == 0)
                    {
                        db.ProductImage.Add(img);
                        db.SaveChanges();
                    }
                    else
                    {
                        var currentItem = db.ProductImage.Where(b => b.Id == img.Id).FirstOrDefault <ProductImage>();
                        currentItem.DisplayOrder = img.DisplayOrder;

                        db.Entry(currentItem).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(Json(data: new { id = img.ProductId, success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewImagesByProduct", model: GetAllImagesByProduct(img.ProductId)), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 14
0
 public ActionResult UpdateRow(Banner model, int Id, int fromPosition, int toPosition)
 {
     using (GerminmedContext db = new GerminmedContext())
     {
         var GenderList = db.Banners.ToList();
         db.Banners.First(c => c.DisplayOrder == Id).DisplayOrder = toPosition;
         db.SaveChanges();
     }
     return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 15
0
        public ActionResult AddOrEdit(Users usr)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (usr.Id == 0)
                    {
                        if (db.User.Any(x => x.UserName == usr.UserName))
                        {
                            return(Json(new { success = false, message = "Username already exist." }, JsonRequestBehavior.AllowGet));
                        }
                        db.User.Add(usr);
                        db.SaveChanges();
                    }
                    else
                    {
                        var currentItem = db.User.Where(b => b.Id == usr.Id).FirstOrDefault <Users>();
                        currentItem.UserName        = usr.UserName;
                        currentItem.FirstName       = usr.FirstName;
                        currentItem.Email           = usr.Email;
                        currentItem.IsAdmin         = usr.IsAdmin;
                        currentItem.ConfirmPassword = currentItem.Password;
                        if (db.User.Any(x => x.UserName == currentItem.UserName && x.Id != currentItem.Id))
                        {
                            return(Json(new { success = false, message = "Username already exist." }, JsonRequestBehavior.AllowGet));
                        }

                        db.Entry(currentItem).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (DataException ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 16
0
        public ActionResult AddOrEdit(Branches brnch)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (brnch.Id == 0)
                    {
                        if (brnch.ImageUpload != null)
                        {
                            string fileName  = Path.GetFileNameWithoutExtension(brnch.ImageUpload.FileName);
                            string extension = Path.GetExtension(brnch.ImageUpload.FileName);
                            fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                            brnch.ImageUrl = "~/AppFiles/Images/" + fileName;
                            brnch.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                        }
                        db.Branch.Add(brnch);
                        db.SaveChanges();
                    }
                    else
                    {
                        var currentItem = db.Branch.Where(b => b.Id == brnch.Id).FirstOrDefault <Branches>();
                        currentItem.Phone           = brnch.Phone;
                        currentItem.Title           = brnch.Title;
                        currentItem.Fax             = brnch.Fax;
                        currentItem.Email           = brnch.Email;
                        currentItem.Location        = brnch.Location;
                        currentItem.PoBox           = brnch.PoBox;
                        db.Entry(currentItem).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (DataException ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 17
0
        public ActionResult AddOrEdit(Clients clns)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (clns.Id == 0)
                    {
                        if (clns.ImageUpload != null)
                        {
                            string fileName  = Path.GetFileNameWithoutExtension(clns.ImageUpload.FileName);
                            string extension = Path.GetExtension(clns.ImageUpload.FileName);
                            fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                            clns.ImageUrl = "~/AppFiles/Images/" + fileName;
                            clns.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                        }
                        db.Client.Add(clns);
                        db.SaveChanges();
                    }
                    else
                    {
                        var currentItem = db.Client.Where(b => b.Id == clns.Id).FirstOrDefault <Clients>();

                        currentItem.Url             = clns.Url;
                        currentItem.DisplayOrder    = clns.DisplayOrder;
                        db.Entry(currentItem).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 18
0
 public ActionResult MailSettings(MailSettings mail)
 {
     try
     {
         using (GerminmedContext db = new GerminmedContext())
         {
             if (mail.Id == 0)
             {
                 db.MailSetting.Add(mail);
                 db.SaveChanges();
             }
             else
             {
                 db.Entry(mail).State = EntityState.Modified;
                 db.SaveChanges();
             }
             return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "MailSettings", model: mail), message = "Mail Settings submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 19
0
 public ActionResult Delete(int Id)
 {
     try
     {
         using (GerminmedContext db = new GerminmedContext())
         {
             Order ord = db.Orders.Where(x => x.Id == Id).FirstOrDefault <Order>();
             db.Orders.Remove(ord);
             db.SaveChanges();
         }
         return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAllOrder()), message = "Deleted Successfully" }, behavior: JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 20
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (GerminmedContext db = new GerminmedContext())
            {
                db.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                                                                // Confirm password does not match issue on save changes
                var v = db.User.Where(a => a.ActivationCode == new Guid(id).ToString()).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
Exemplo n.º 21
0
        public ActionResult AddOrEdit(Category catg, FormCollection fobj)
        {
            try
            {
                using (GerminmedContext db = new GerminmedContext())
                {
                    if (catg.InnerBannerImageUpload != null)
                    {
                        string fileName  = Path.GetFileNameWithoutExtension(catg.InnerBannerImageUpload.FileName);
                        string extension = Path.GetExtension(catg.InnerBannerImageUpload.FileName);
                        fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        catg.InnerBannerImageUrl = "~/AppFiles/Images/" + fileName;
                        catg.InnerBannerImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                    }
                    else
                    {
                        catg.InnerBannerImageUrl = null;
                    }

                    if (catg.Id == 0)
                    {
                        if (catg.ImageUpload != null)
                        {
                            string fileName  = Path.GetFileNameWithoutExtension(catg.ImageUpload.FileName);
                            string extension = Path.GetExtension(catg.ImageUpload.FileName);
                            fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                            catg.ImageUrl = "~/AppFiles/Images/" + fileName;
                            catg.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                        }
                        else
                        {
                            catg.ImageUrl = null;
                        }

                        db.Category.Add(catg);
                        db.SaveChanges();
                    }
                    else
                    {
                        //if (catg.ImageUpload != null)
                        //{
                        //    string fileName = Path.GetFileNameWithoutExtension(catg.ImageUpload.FileName);
                        //    string extension = Path.GetExtension(catg.ImageUpload.FileName);
                        //    fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        //    catg.ImageUrl = "~/AppFiles/Images/" + fileName;
                        //    catg.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                        //}
                        //else
                        //{
                        //    catg.ImageUrl = null;
                        //}
                        var currentItem = db.Category.Where(b => b.Id == catg.Id).FirstOrDefault <Category>();
                        currentItem.Title               = catg.Title;
                        currentItem.ParentId            = catg.ParentId;
                        currentItem.Description         = catg.Description;
                        currentItem.InnerBannerImageUrl = catg.InnerBannerImageUrl;
                        //  currentItem.ImageUrl = catg.ImageUrl;

                        db.Entry(currentItem).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                }
                return(Json(data: new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", model: GetAll()), message = "Submitted Successfully" }, behavior: JsonRequestBehavior.AllowGet));

                //RedirectToAction("ViewAll");
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }