public ActionResult AddEmployee(Employee e, ImageFile photo, string webpage, string tmpl) { string dbPhotoPath = ""; if (photo != null) { photo.ValidateForUpload(true); if (ModelState.IsValid) { if (photo.Save("emp", new System.Drawing.Size(Config.Employee.Photo.Width, Config.Employee.Photo.Height), false)) { dbPhotoPath = "/" + photo.SavePath; } } } else { ModelState.AddModelError("photo", "Photo does not exist."); } if (!string.IsNullOrEmpty(dbPhotoPath)) { if(ModelState.IsValid) { DBDataContext db = Utils.DB.GetContext(); WebPage page = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webpage)); if (page != null) { Employee emp = new Employee() { FirstName = e.FirstName, LastName = e.LastName, Title = e.Title, Description = e.Description, EmailAddress = e.EmailAddress, Photo = dbPhotoPath }; page.Employees.Add(emp); try { db.SubmitChanges(); return RedirectToAction("Employees", "Body", new { controller = "Body", action = "Employees", webpage = webpage, tmpl = tmpl }); } catch(Exception ex) { ModelState.AddModelError("", "An unknown error occurred. Please try again in few minutes."); ErrorHandler.Report.Exception(ex, "Body/AddEmployee[HTTPPOST]"); } } else { ModelState.AddModelError("", "Web Page does not exist."); } } } if(System.IO.File.Exists(HttpContext.Server.MapPath(dbPhotoPath))) { System.IO.File.Delete(HttpContext.Server.MapPath(dbPhotoPath)); } ViewData["WebPageID"] = webpage; ViewData["Template"] = tmpl; ViewData["Title"] = "Add Employee"; ViewData["Action"] = "AddEmployee"; return View("ManageEmployee", e); }
partial void DeleteEmployee(Employee instance);
partial void UpdateEmployee(Employee instance);
partial void InsertEmployee(Employee instance);
private void detach_Employees(Employee entity) { this.SendPropertyChanging(); entity.WebPage = null; }
private void attach_Employees(Employee entity) { this.SendPropertyChanging(); entity.WebPage = this; }