public string AddEmpWithImage(UIEmp uiEmp) { HttpPostedFileBase imgFile = Request.Files["ProfilePic"]; BinaryReader br = new BinaryReader(imgFile.InputStream); byte[] bytes = br.ReadBytes(Convert.ToInt32(imgFile.ContentLength)); uiEmp.ProfilePic = new UIProfilePic(); uiEmp.ProfilePic.ProfileImage = bytes; Employee employee = new Employee(); employee.FirstName = uiEmp.FirstName; employee.LastName = uiEmp.LastName; employee.GenderId = uiEmp.Gender.GenderId; employee.MobileNo = uiEmp.MobileNo; employee.EmailId = uiEmp.EmailId; employee.CountryId = uiEmp.Country.CountryId; employee.StateId = uiEmp.State.StateId; employee.Address = uiEmp.Address; employee.ZipCode = uiEmp.ZipCode; mvcDemoEntities.Employees.Add(employee); int status = mvcDemoEntities.SaveChanges(); int empId = employee.EmployeeId; if (status > 0) { ProfilePic profilePic = new ProfilePic(); profilePic.ProfileImage = uiEmp.ProfilePic.ProfileImage; profilePic.EmployeeId = empId; mvcDemoEntities.ProfilePics.Add(profilePic); int res = mvcDemoEntities.SaveChanges(); } return(""); }
public ActionResult Test() { UIEmp uiEmp = new UIEmp(); int year = DateTime.Now.Year; uiEmp.lstCountry = (from c in mvcDemoEntities.Countries select new UICountry { Name = c.Name, CountryId = c.CountryId }).ToList(); uiEmp.lstGender = (from g in mvcDemoEntities.Genders select new UIGender { Name = g.Name, GenderId = g.GenderId }).ToList(); //uiEmp.lstState.Add(new UIState() //{ // StateId = 1, // Name = "" //}); uiEmp.lstQualification = (from q in mvcDemoEntities.Qualifications select new UIQualification { QualificationId = q.QualificationID, Qualification = q.Qualification1 }).ToList(); uiEmp.lstState = new List <UIState>(); List <PassYear> years = new List <PassYear>(); for (int i = year; i >= 2000; i--) { PassYear passYear = new PassYear(); passYear.Passyear = i; passYear.YearOfPassing = i; years.Add(passYear); } uiEmp.lstYear = years; return(View(uiEmp)); }
public JsonResult AddEmpEdit(string id) { UIEmp emp = new UIEmp() { FirstName = "Praveen", LastName = "Kumar", DateofBirth = "123654", Address = "HYD" }; return(Json(emp, JsonRequestBehavior.AllowGet)); }
public ActionResult AddEmp() { UIEmp uiEmp = new UIEmp(); // List<UICountry> lstc = new List<UICountry>(); // mvcDemoEntities.Countries.ToList().ForEach(o => lstc.Add(new UICountry { Name = o.Name, CountryId = o.CountryId })); uiEmp.lstCountry = (from c in mvcDemoEntities.Countries select new UICountry { Name = c.Name, CountryId = c.CountryId }).ToList(); uiEmp.lstGender = (from g in mvcDemoEntities.Genders select new UIGender { Name = g.Name, GenderId = g.GenderId }).ToList(); uiEmp.lstState = new List <UIState>(); uiEmp.lstState.Add(new UIState() { StateId = 0, Name = "" }); return(View(uiEmp)); }
public ActionResult EditEmps(string empId) { UIEmp uiEmp = new UIEmp(); int id = Convert.ToInt32(empId); uiEmp = (from e in mvcDemoEntities.Employees.Where(o => o.EmployeeId == id) select new UIEmp { EmployeeId = e.EmployeeId, FirstName = e.FirstName, LastName = e.LastName, Gender = new UIGender { GenderId = e.GenderId }, Country = new UICountry { CountryId = e.CountryId }, State = new UIState { StateId = e.StateId }, MobileNo = e.MobileNo, EmailId = e.EmailId, Address = e.Address, ZipCode = e.ZipCode, }).FirstOrDefault(); uiEmp.lstCountry = (from c in mvcDemoEntities.Countries select new UICountry { Name = c.Name, CountryId = c.CountryId }).ToList(); uiEmp.lstGender = (from g in mvcDemoEntities.Genders select new UIGender { Name = g.Name, GenderId = g.GenderId }).ToList(); uiEmp.lstState = (from s in mvcDemoEntities.States join e in mvcDemoEntities.Employees.Where(o => o.EmployeeId == id) on s.CountryId equals e.CountryId select new UIState { Name = s.Name, StateId = s.StateId }).ToList(); return(View("AddEmp", uiEmp)); }
public ActionResult AddEmpDetails(UIEmp emp) { return(View()); }
public ActionResult AddEmp1(UIEmp uiEmp) { string statusMsg = string.Empty; try { int empId = uiEmp.EmployeeId; int status = 0; HttpPostedFileBase imgFile = Request.Files["ProfilePic"]; BinaryReader br = new BinaryReader(imgFile.InputStream); byte[] bytes = br.ReadBytes(Convert.ToInt32(imgFile.ContentLength)); uiEmp.ProfilePic = new UIProfilePic(); uiEmp.ProfilePic.ProfileImage = bytes; if (empId == 0) { Employee employee = new Employee(); employee.FirstName = uiEmp.FirstName; employee.LastName = uiEmp.LastName; employee.MobileNo = uiEmp.MobileNo; employee.EmailId = uiEmp.EmailId; employee.Address = uiEmp.Address; employee.ZipCode = uiEmp.ZipCode; employee.GenderId = uiEmp.Gender.GenderId; employee.CountryId = uiEmp.Country.CountryId; employee.StateId = uiEmp.State.StateId; employee.StatusTypeId = 1; mvcDemoEntities.Employees.Add(employee); status = mvcDemoEntities.SaveChanges(); int id = employee.EmployeeId; if (status > 0) { if (imgFile.ContentLength != 0) { ProfilePic profilePic = new ProfilePic(); profilePic.ProfileImage = uiEmp.ProfilePic.ProfileImage; profilePic.EmployeeId = id; mvcDemoEntities.ProfilePics.Add(profilePic); int res = mvcDemoEntities.SaveChanges(); } statusMsg = "Add"; } } else { var lstEmp = mvcDemoEntities.Employees.Find(empId); lstEmp.FirstName = uiEmp.FirstName; lstEmp.LastName = uiEmp.LastName; lstEmp.MobileNo = uiEmp.MobileNo; lstEmp.EmailId = uiEmp.EmailId; lstEmp.Address = uiEmp.Address; lstEmp.ZipCode = uiEmp.ZipCode; lstEmp.GenderId = uiEmp.Gender.GenderId; lstEmp.CountryId = uiEmp.Country.CountryId; lstEmp.StateId = uiEmp.State.StateId; mvcDemoEntities.Entry(lstEmp).State = EntityState.Modified; status = mvcDemoEntities.SaveChanges(); if (status > 0) { if (mvcDemoEntities.ProfilePics.Any(o => o.EmployeeId == empId)) { if (imgFile.ContentLength != 0) { var obj = mvcDemoEntities.ProfilePics.FirstOrDefault(o => o.EmployeeId == empId); mvcDemoEntities.ProfilePics.Remove(obj); mvcDemoEntities.Entry(obj).State = EntityState.Deleted; int i = mvcDemoEntities.SaveChanges(); ProfilePic profilePic = new ProfilePic(); profilePic.ProfileImage = uiEmp.ProfilePic.ProfileImage; profilePic.EmployeeId = empId; mvcDemoEntities.ProfilePics.Add(profilePic); int res = mvcDemoEntities.SaveChanges(); obj.ProfileImage = uiEmp.ProfilePic.ProfileImage; status = mvcDemoEntities.SaveChanges(); } } else { ProfilePic profilePic = new ProfilePic(); profilePic.ProfileImage = uiEmp.ProfilePic.ProfileImage; profilePic.EmployeeId = empId; mvcDemoEntities.ProfilePics.Add(profilePic); int res = mvcDemoEntities.SaveChanges(); } statusMsg = "Update"; } } } catch (Exception ex) { statusMsg = "Error"; } //return RedirectToAction("jqEmpsList"); return(Redirect("jqEmpsList?status=" + statusMsg)); }
public string EmpEducation(UIEmp UiEmp) { return(""); }