public ActionResult Create(EmployeeCreateModel model) { try { var imageName = string.Empty; if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { var EmpPhoto = System.Web.HttpContext.Current.Request.Files["file"]; if (EmpPhoto.ContentLength > 0) { var profileName = Path.GetFileName(EmpPhoto.FileName); var ext = Path.GetExtension(EmpPhoto.FileName); imageName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ext; var comPath = Server.MapPath("/Images/") + imageName; EmpPhoto.SaveAs(comPath); } } else { imageName = model.EmployeePhoto; } var dbContext = new ExcellenceITEntities(); var datamodel = new TBL_Employee { CityID = model.CityID, StateID = model.StateID, Pincode = model.Pincode, CountryID = model.CountryID, Department = model.Department, Email = model.Email, EmpID = model.EmpID, FirstName = model.FirstName, LastName = model.LastName, Gender = model.Gender, Hobbies = model.Hobbies, Phone = model.Phone, DOB = model.DOB, EmployeePhoto = imageName }; if (model.EmpID > 0) { dbContext.Entry(datamodel).State = System.Data.Entity.EntityState.Modified; TempData["Message"] = "Emplyoyee Updated Suceessfully"; } else { dbContext.TBL_Employee.Add(datamodel); TempData["Message"] = "Emplyoyee Added Suceessfully"; } dbContext.SaveChanges(); return(Json(new { isSuccess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { isSuccess = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteEmp(int?id) { try { var dbContext = new ExcellenceITEntities(); var EmpData = dbContext.TBL_Employee.Where(x => x.EmpID == id).FirstOrDefault(); dbContext.TBL_Employee.Remove(EmpData); dbContext.SaveChanges(); return(Json(new { isSuccess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { isSuccess = false }, JsonRequestBehavior.AllowGet)); } }