Esempio n. 1
0
        public IHttpActionResult UpdateItem(int id, MyDBModel details)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            using (todoDBEntities1 db = new todoDBEntities1())
            {
                db.Entry(details).State = System.Data.EntityState.Modified;



                try
                {
                    db.SaveChanges();
                }

                catch (Exception ec)
                {
                    Console.WriteLine(ec.Message);
                }
            }

            return(Ok(details));
        }
Esempio n. 2
0
        public IHttpActionResult DeleteItem(int id)
        {
            if (!ModelState.IsValid || id == null)
            {
                return(BadRequest(ModelState));
            }



            using (todoDBEntities1 db = new todoDBEntities1())
            {
                MyDBModel tmp = db.MyDBModels.Find(id);
                db.MyDBModels.Remove(tmp);



                try
                {
                    db.SaveChanges();
                }

                catch (Exception ec)
                {
                    Console.WriteLine(ec.Message);
                }
            }

            return(Ok());
        }
 public ActionResult GetData()
 {
     using (MyDBModel db = new MyDBModel())
     {
         List <Employee> empList = db.Employee.ToList();
         return(Json(new { data = empList }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult Delete(int id)
 {
     using (MyDBModel db = new MyDBModel())
     {
         Employee emp = db.Employee.Where(x => x.EmployeeID == id).FirstOrDefault();
         db.Employee.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         return(View(new Employee()));
     }
     else
     {
         using (MyDBModel db = new MyDBModel())
         {
             return(View(db.Employee.Where(x => x.EmployeeID == id).FirstOrDefault()));
         }
     }
 }
 public ActionResult AddOrEdit(Employee emp)
 {
     using (MyDBModel db = new MyDBModel())
     {
         if (emp.EmployeeID == 0)
         {
             db.Employee.Add(emp);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(emp).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
        public ActionResult Login(Admin adm)
        {
            using (MyDBModel db = new MyDBModel())
            {
                try
                {
                    var check = db.Admin.Single(x => x.AdminName == adm.AdminName && x.AdminPassword == adm.AdminPassword);
                    if (check != null)
                    {
                        Session["AdminId"]   = adm.AdminId.ToString();
                        Session["AdminName"] = adm.AdminName.ToString();
                        return(RedirectToAction("Index"));
                    }
                }catch (Exception)
                {
                    TempData["Message"] = "Login failed - wrong Name or Password";
                }
            }

            return(View(adm));
        }
Esempio n. 8
0
        public IHttpActionResult Create([FromBody] MyDBModel item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            using (todoDBEntities1 db = new todoDBEntities1())
            {
                db.MyDBModels.Add(item);
                try
                {
                    db.SaveChanges();
                }

                catch (Exception ec)
                {
                    Console.WriteLine(ec.Message);
                }
            }


            return(Ok(item));
        }
 public ProductController()
 {
     _dbContext = new Models.MyDBModel();
 }
Esempio n. 10
0
 public OneDollar112ViewModel(Int32 number)
 {
     myModel = db.MyTable
               .Where(t => t.Current == 1 && t.No == numbner).SingleOrDefault();
 }