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"));
        }
        // GET: Company
        public ActionResult Index()
        {
            List <Company> companies;

            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                companies = db.Companies.ToList();
            }

            return(View(companies));
        }
        public ActionResult Edit(int id)
        {
            Company company;

            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                company = db.Companies.FirstOrDefault(c => c.Id == id);
            }

            ViewBag.FormTitle  = "Update Company";
            ViewBag.FormButton = "Update";

            return(View("CompanyForm", company));
        }
Example #5
0
        public ActionResult Create()
        {
            EmployeeFormViewModel model = new EmployeeFormViewModel();

            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                model.Companies = db.Companies.ToList();
            }

            model.Action       = "Create";
            model.FormTitle    = "Create New Employee";
            model.SubmitButton = "Save";

            return(View("EmployeeForm", model));
        }
Example #6
0
        public ActionResult Edit(int id)
        {
            EmployeeFormViewModel model = new EmployeeFormViewModel();

            using (P210_MVCEntities db = new P210_MVCEntities())
            {
                model.Companies = db.Companies.ToList();
                model.Employee  = db.Employees.FirstOrDefault(e => e.Id == id);
            }

            model.Action       = "Edit";
            model.FormTitle    = "Update " + model.Employee.Name + " " + model.Employee.Surname;
            model.SubmitButton = "Update";

            return(View("EmployeeForm", model));
        }
Example #7
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"));
        }
Example #9
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"));
        }