public ActionResult NewInvToEvent(int id) { var appEventId = Convert.ToInt32(TempData["IdOfCurrentEvent"]); TempData["idOfEventPassToInv"] = appEventId; var userIdToPass = User.Identity.GetUserId(); var user = _context.Users.FirstOrDefault(u => u.Id == userIdToPass); var appUserToPass = _context.AppUsers.SingleOrDefault(c => c.Id == user.AppUserId); var professionalToInv = _context.Professionals.SingleOrDefault(m => m.Id == id); var eventToInv = _context.Events.SingleOrDefault(m => m.Id == appEventId); var invStatus = _context.InvitationStatuses.ToList(); TempData["professionalToInv"] = professionalToInv.Id; var viewModel = new EventProfessionalForm() { //AppEvent = eventToInv, InvitationStatuses = invStatus //Professional = professionalToInv }; return(View("EventProfessionalForm", viewModel)); }
public ActionResult SaveProfessionalToEvent(EventProfessionalForm _eventProfessional, int id = 0) { //_eventProfessional.EventProfessional.InvitationStatusId = 1; var appEventId = Convert.ToInt32(TempData["idOfEventPassToInv"]); // IdOfCurrentEvent id = Convert.ToInt32(TempData["professionalToInv"]); var userIdToPass = User.Identity.GetUserId(); var user = _context.Users.FirstOrDefault(u => u.Id == userIdToPass); _eventProfessional.EventProfessional.Importance = Convert.ToDouble(_eventProfessional.ScoringRange); var appUserToPass = _context.AppUsers.SingleOrDefault(c => c.Id == user.AppUserId); var professionalToInv = _context.Professionals.SingleOrDefault(m => m.Id == id); var eventToInv = _context.Events.SingleOrDefault(m => m.Id == appEventId); var invStatus = _context.InvitationStatuses.SingleOrDefault(m => m.Id == _eventProfessional.EventProfessional.InvitationStatusId); var invStatus_Pending = _context.InvitationStatuses.SingleOrDefault(m => m.Name == "Pending"); var inv = new EventProfessional() { Comment = _eventProfessional.EventProfessional.Comment, Importance = _eventProfessional.EventProfessional.Importance, Price = _eventProfessional.EventProfessional.Price, DateOfJob = eventToInv.Date, ProfessionalId = professionalToInv.Id, Professional = professionalToInv, InvitationStatusId = /*_eventProfessional.EventProfessional.InvitationStatusId*/ invStatus_Pending.Id, InvitationStatus = invStatus_Pending, AppEvent = eventToInv, AppEventId = appEventId, Rola = "AppUser" }; // _context.EventProfessionals.Add(inv); _context.SaveChanges(); //return View(); return(RedirectToAction("Index", "AppEvents")); }
public ActionResult SaveProfessionalToEventFromPro(EventProfessionalForm _eventProfessional, int id = 0) { var appEventId = Convert.ToInt32(TempData["idOfEventPassToInvPro"]); // IdOfCurrentEvent id = Convert.ToInt32(TempData["professionalToInvPro"]); var userIdToPass = User.Identity.GetUserId(); var professionalToInv = _context.Professionals.SingleOrDefault(m => m.CurrentUserId == userIdToPass); var eventToInv = _context.Events.SingleOrDefault(m => m.Id == appEventId); if (_eventProfessional.EventProfessional.DateOfJob < new DateTime(1999, 1, 1)) { _eventProfessional.EventProfessional.DateOfJob = eventToInv.Date; } //.EventProfessional.DateOfJob = eventToInv.Date; var invStatus_Pending = _context.InvitationStatuses.SingleOrDefault(m => m.Name == "Pending"); var inv = new EventProfessional() { Comment = _eventProfessional.EventProfessional.Comment, Importance = _eventProfessional.EventProfessional.Importance, Price = _eventProfessional.EventProfessional.Price, DateOfJob = _eventProfessional.EventProfessional.DateOfJob, ProfessionalId = professionalToInv.Id, Professional = professionalToInv, InvitationStatusId = invStatus_Pending.Id, InvitationStatus = invStatus_Pending, AppEvent = eventToInv, AppEventId = appEventId, Rola = "Professional" }; _context.EventProfessionals.Add(inv); _context.SaveChanges(); return(RedirectToAction("Index", "AppEvents")); }