Example #1
0
        public ActionResult EditHandySample(Tbl_HandySample s)
        {
            String Message = "";

            if (Session["UserName"] == null)
            {
                Message = "Access denied. need login.";
                log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.EventLog);
                return(RedirectToAction("Index", "Account", new { returnUrl = "/HandySample/Index" }));
            }

            else if (Session["RoleName"].ToString() == "Admin")
            {
                try
                {
                    InitDropdownLists();
                    var sample = db.Tbl_HandySample.Where(a => a.HandySample_ID == s.HandySample_ID).SingleOrDefault();
                    if (sample != null)
                    {
                        sample.HandySample_Perfume_ID  = s.HandySample_Perfume_ID;
                        sample.HandySample_AllWeight   = s.HandySample_AllWeight;
                        sample.HandySample_PricePerMil = s.HandySample_PricePerMil;
                        db.Tbl_HandySample.Attach(sample);
                        db.Entry(sample).State = System.Data.Entity.EntityState.Modified;
                        if (Convert.ToBoolean(db.SaveChanges() > 0))
                        {
                            Message = "handy sample with id " + s.HandySample_ID + " edited successfully.";
                            log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.EventLog);
                            return(RedirectToAction("Index", "HandySample"));
                        }
                        else
                        {
                            Message = "edited handy sample with id " + s.HandySample_ID + " failed.";
                            log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.ErrorLog);
                            return(RedirectToAction("Index", "HandySample"));
                        }
                    }
                    else
                    {
                        Message = "handy sample with ID" + s.HandySample_ID + "not found.";
                        log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.EventLog);
                        ViewBag.Error = "محصول پیدا نشد، لطفا دوباره تلاش کنید.";
                        return(RedirectToAction("Index", "HandySample"));
                    }
                }
                catch
                {
                    Message = "handy sample with ID" + s.HandySample_ID + "not found.";
                    log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.EventLog);
                    ViewBag.Error = "محصول پیدا نشد، لطفا دوباره تلاش کنید.";
                    return(View());
                }
            }
            else
            {
                Message = "You do not have access to this page.";
                log.addLog(Message, "EditHandySample", "DashboardHandySample", logStatus.EventLog);
                return(RedirectToAction("Error404", "Home"));
            }
        }
Example #2
0
        public ActionResult AddHandySample(Tbl_HandySample sample)
        {
            String Message = "";

            if (Session["UserName"] == null)
            {
                Message = "Access denied. need login.";
                log.addLog(Message, "AddHandySample", "DashboardHandySample", logStatus.EventLog);
                return(RedirectToAction("Index", "Account", new { returnUrl = "/HandySample/Index" }));
            }
            else if (Session["RoleName"].ToString() == "Admin")
            {
                try
                {
                    InitDropdownLists();
                    Tbl_HandySample s = new Tbl_HandySample();
                    s.HandySample_Perfume_ID  = sample.HandySample_Perfume_ID;
                    s.HandySample_PricePerMil = sample.HandySample_PricePerMil;
                    s.HandySample_AllWeight   = sample.HandySample_AllWeight;
                    db.Tbl_HandySample.Add(s);
                    if (Convert.ToBoolean(db.SaveChanges() > 0))
                    {
                        Message = "handy sample with perfume ID " + sample.HandySample_Perfume_ID + " added successfully.";
                        log.addLog(Message, "AddHandySample", "DashboardHandySample", logStatus.EventLog);
                        return(RedirectToAction("Index", "HandySample"));
                    }
                    else
                    {
                        Message = "added handy sample with perfume ID " + sample.HandySample_Perfume_ID + " failed.";
                        log.addLog(Message, "AddHandySample", "DashboardHandySample", logStatus.ErrorLog);
                        ViewBag.Error = "سمپل جدید ثبت نشد، لطفا دوباره تلاش کنید.";
                        return(View());
                    }
                }
                catch
                {
                    Message = "added handy sample with perfume ID " + sample.HandySample_Perfume_ID + " failed.";
                    log.addLog(Message, "AddHandySample", "DashboardHandySample", logStatus.ErrorLog);
                    ViewBag.Error = "سمپل جدید ثبت نشد، لطفا دوباره تلاش کنید.";
                    return(View());
                }
            }
            else
            {
                Message = "You do not have access to this page.";
                log.addLog(Message, "AddHandySample", "DashboardHandySample", logStatus.EventLog);
                return(RedirectToAction("Error404", "Home"));
            }
        }