Ejemplo n.º 1
0
        public ActionResult Add(User model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string fileName      = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
                    string fileExtention = Path.GetExtension(model.ImageFile.FileName);
                    fileName        = fileName + DateTime.Now.ToString("yymmssfff") + fileExtention;
                    model.ImagePath = "~/Images/ProfileImages/" + fileName;
                    fileName        = Path.Combine(Server.MapPath("~/Images/ProfileImages/"), fileName);
                    model.ImageFile.SaveAs(fileName);


                    PMISContext db = new PMISContext();
                    db.Users.Add(model);
                    db.SaveChanges();
                    TempData["ADD_STATE"] = "OK";
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                TempData["ADD_STATE"] = "متاسفانه عملیات با خطا مواجه شد";
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Ejemplo n.º 2
0
 public ActionResult Delete(int id)
 {
     try
     {
         PMISContext db     = new PMISContext();
         var         person = db.Persons.First(o => o.ID == id);
         db.Persons.Remove(person);
         db.SaveChanges();
         return(null);
     }
     catch (Exception e)
     {
         return(Json("امکان حذف این ساختار وجود ندارد"));
     }
 }
Ejemplo n.º 3
0
 public ActionResult Add(Person model)
 {
     try
     {
         PMISContext db = new PMISContext();
         db.Persons.Add(model);
         db.SaveChanges();
         TempData["ADD_STATE"] = "OK";
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         TempData["ADD_STATE"] = "متاسفانه عملیات با خطا مواجه شد";
         return(RedirectToAction("Index"));
     }
 }
Ejemplo n.º 4
0
 public ActionResult Edit(Organization model)
 {
     try
     {
         PMISContext db  = new PMISContext();
         var         org = db.Organizations.Where(x => x.ID == model.ID).SingleOrDefault();
         db.Entry(org).CurrentValues.SetValues(model);
         db.SaveChanges();
         TempData["EDIT_STATE"] = "OK";
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         TempData["EDIT_STATE"] = "FAIL";
         return(RedirectToAction("Index"));
     }
 }
Ejemplo n.º 5
0
 public ActionResult Edit(Person model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             PMISContext db  = new PMISContext();
             var         org = db.Persons.Where(x => x.ID == model.ID).SingleOrDefault();
             db.Entry(org).CurrentValues.SetValues(model);
             db.SaveChanges();
             TempData["EDIT_STATE"] = "OK";
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(model));
         }
     }
     catch (Exception e)
     {
         TempData["EDIT_STATE"] = "FAIL";
         return(RedirectToAction("Index"));
     }
 }
Ejemplo n.º 6
0
 public ActionResult Add(Organization model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             PMISContext db = new PMISContext();
             db.Organizations.Add(model);
             db.SaveChanges();
             TempData["ADD_STATE"] = "OK";
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["ADD_STATE"] = "فیلدهای خواسته شده را به درستی وارد نکرده اید";
             return(View());
         }
     }
     catch (Exception e)
     {
         TempData["ADD_STATE"] = "متاسفانه عملیات با خطا مواجه شد";
         return(RedirectToAction("Index"));
     }
 }