public ActionResult Create(Company company)
        {
            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                db.Companies.Add(company);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(Company company)
        {
            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                db.Entry(company).State = EntityState.Modified;
                db.SaveChanges();
            }

            //db.Entry(company).Property("Id").IsModified = false;
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult Create(Employee employee, HttpPostedFileBase Photo)
        {
            if (Photo != null)
            {
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Photo.FileName;
                employee.Photo = fileName;
                Photo.SaveAs(Path.Combine(Server.MapPath("~"), "Uploads", fileName));
            }


            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                db.Employees.Add(employee);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id)
        {
            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                Company company = db.Companies.FirstOrDefault(c => c.Id == id);
                if (company != null)
                {
                    db.Companies.Remove(company);
                    db.SaveChanges();
                }
                else
                {
                    return(HttpNotFound());
                }
            }

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ActionResult Edit(Employee employee, HttpPostedFileBase Photo)
        {
            if (Photo != null)
            {
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Photo.FileName;
                employee.Photo = fileName;
                Photo.SaveAs(Path.Combine(Server.MapPath("~"), "Uploads", fileName));
            }

            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                db.Entry(employee).State = EntityState.Modified;


                //if (employee.Photo == null)
                //{
                //    db.Entry(employee).Property(p => p.Photo).IsModified = false;
                //}

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }