예제 #1
0
 public ActionResult SaveState(SA_States model)
 {
     if (model.Id == 0)
     {
         var check = _context.SA_States.Where(w => w.State == model.State).FirstOrDefault();
         if (check != null)
         {
             TempData["Message"] = "This state is already exist!";
             return(RedirectToAction("AddState"));
         }
         else
         {
             SA_States Obj = new SA_States();
             Obj.CountryId   = model.CountryId;
             Obj.State       = model.State;
             Obj.CreatedTime = DateTime.Now;
             _context.SA_States.Add(Obj);
             _context.SaveChanges();
         }
     }
     else
     {
         var Obj = _context.SA_States.Where(w => w.Id == model.Id).FirstOrDefault();
         Obj.CountryId = model.CountryId;
         Obj.State     = model.State;
         _context.SaveChanges();
         return(RedirectToAction("ShowStateList"));
     }
     return(RedirectToAction("ShowStateList"));
 }
예제 #2
0
        public ActionResult EditState(int id)
        {
            ChemAnalystContext _context = new ChemAnalystContext();

            SA_States obj = _context.SA_States.Where(w => w.Id == id).FirstOrDefault();

            return(View("add-state", obj));
        }
예제 #3
0
        public ActionResult Deletestate(int id)
        {
            try
            {
                SA_States state = _context.SA_States.Where(c => c.Id == id).FirstOrDefault();
                _context.Entry(state).State = EntityState.Deleted;
                int x = _context.SaveChanges();

                return(RedirectToAction("ShowStateList"));
            }
            catch (Exception ex)
            {
                return(View("ErrorEventArgs"));
            }
        }