public ActionResult Create(VolunteerRegistrationVM model) { try { if (ModelState.IsValid) { var file = model.Photo; if (file != null) { Volunteer volunteer = new Volunteer { Name = model.Name, Email = model.Email, Phone = model.Phone, Address = model.Address, Gender = model.Gender, DateOfBirth = model.DateOfBirth, EverVolunteered = model.EverVolunteered, Note = model.Note, AddDate = DateTime.Now, Status = "Pending", }; volunteerService.Insert(volunteer); int id = volunteer.Id; volunteer.PhotoPath = "/Images/Volunteers/" + id + ".jpg"; file.SaveAs(Server.MapPath("/Images/Volunteers/" + id + ".jpg")); volunteerService.Update(volunteer); ViewBag.Message = "Volunteer data added successfully."; } else { ViewBag.Error = "Image not found!"; } } } catch (Exception e) { ViewBag.Exception = e.InnerException.InnerException.Message; ViewBag.Error = "Something went wrong!"; } return(View(model)); }
public ActionResult VolunteerRegistration(VolunteerRegistrationVM model) { try { if (ModelState.IsValid) { var file = model.Photo; if (file != null) { Volunteer volunteer = new Volunteer { Name = model.Name, Email = model.Email, Phone = model.Phone, Address = model.Address, Gender = model.Gender, DateOfBirth = model.DateOfBirth, EverVolunteered = model.EverVolunteered, Note = model.Note, AddDate = DateTime.Now, Status = "Pending" }; volunteerService.Insert(volunteer); int id = volunteer.Id; volunteer.PhotoPath = "/Images/Volunteers/" + id + ".jpg"; file.SaveAs(Server.MapPath("/Images/Volunteers/" + id + ".jpg")); volunteerService.Update(volunteer); ViewBag.Message = "Thank you for applying as a volunteer. We will contact you as soon as possible."; } } } catch (Exception e) { ViewBag.Error = "Something went wrong! We are Sorry for your inconvenience."; ViewBag.Exception = e.Message; } return(View(model)); }