public virtual ActionResult Create(int id) { var memberId = WebHelper.GetIdentityId(User.Identity); //if (memberId == 0) // return View(MVC.Shared.Views.Error); var context = ModelFactory.GetUnitOfWork(); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); var oRepo = ModelFactory.GetRepository<IOfferRepository>(context); var offer = oRepo.Get(id); var member = mRepo.Get(memberId); var formModel = new MemberBookingFormViewModel(member, offer); return View(formModel); }
public virtual ActionResult Create(int id, MemberBookingFormViewModel formData) { var context = ModelFactory.GetUnitOfWork(); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); var oRepo = ModelFactory.GetRepository<IOfferRepository>(context); var memberId = WebHelper.GetIdentityId(User.Identity); var member = mRepo.Get(memberId); var offer = oRepo.Get(id); if (ModelState.IsValid) { var sendNewAccountMail = false; try { var memberData = new MemberMainData { FirstName = formData.FirstName, LastName = formData.LastName, PhoneNumber = formData.PhoneNumber, }; sendNewAccountMail = _MembershipService.TryCreateAccount(formData.Email, memberData, out memberId); member = mRepo.Get(memberId); var locName = offer.Localisation.Name; var locUrl = offer.Localisation.GetDetailFullUrl(Url); try { formData.MemberBooking.MemberId = memberId; formData.MemberBooking.OfferId = id; formData.MemberBooking.StatusId = (int)MemberBooking.Status.Unknown; formData.AjustBookingPeriod(); formData.MemberBooking.Price = offer.GetDefaultPrice(formData.MemberBooking.FromDate, formData.MemberBooking.ToDate, formData.MemberBooking.PeriodType == (int)MemberBooking.ePeriodType.SpendUnit, (Offer.PaymentPeriod)formData.MemberBooking.TimeType, formData.MemberBooking.TimeUnits); //set phone number to the one from form member.MemberMainData.PhoneNumber = formData.PhoneNumber; member.MemberBookings.Add(formData.MemberBooking); formData.MemberBooking.MemberBookingLogs.Add(new MemberBookingLog { CreatedDate = DateTime.UtcNow, Event = "Booking Created", EventType = (int)MemberBookingLog.BookingEvent.Creation, LoggerId = memberId }); formData.MemberBooking.InvoiceNumber = new InvoiceNumber(); if (!offer.Localisation.HasClient(memberId)) { offer.Localisation.LocalisationClients.Add(new LocalisationClient { ClientId = memberId }); } object newMemberMail = null; if (sendNewAccountMail) { var urlHelper = new UrlHelper(ControllerContext.RequestContext); var editprofilUrl = urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit()); TagBuilder profilLink = new TagBuilder("a"); profilLink.MergeAttribute("href", editprofilUrl); profilLink.InnerHtml = Worki.Resources.Views.Account.AccountString.EditMyProfile; var editpasswordUrl = urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit()); TagBuilder passwordLink = new TagBuilder("a"); passwordLink.MergeAttribute("href", editpasswordUrl); passwordLink.InnerHtml = Worki.Resources.Views.Account.AccountString.ChangeMyPassword; var newMemberMailContent = string.Format(Worki.Resources.Email.BookingString.BookingNewMember, Localisation.GetOfferType(offer.Type), formData.MemberBooking.GetStartDate(), formData.MemberBooking.GetEndDate(), locName, offer.Localisation.Adress, formData.Email, _MembershipService.GetPassword(formData.Email, null), passwordLink, profilLink); newMemberMail = _EmailService.PrepareMessageFromDefault(new MailAddress(formData.Email, formData.FirstName), Worki.Resources.Email.BookingString.BookingNewMemberSubject, WebHelper.RenderEmailToString(formData.FirstName, newMemberMailContent)); } //send mail to team var teamMailContent = string.Format(Worki.Resources.Email.BookingString.CreateBookingTeam, string.Format("{0} {1}", member.MemberMainData.FirstName, member.MemberMainData.LastName), formData.PhoneNumber, member.Email, locName, Localisation.GetOfferType(offer.Type), formData.MemberBooking.GetStartDate(), formData.MemberBooking.GetEndDate(), formData.MemberBooking.Message, locUrl); var teamMail = _EmailService.PrepareMessageToDefault(new MailAddress(MiscHelpers.EmailConstants.BookingMail, MiscHelpers.EmailConstants.ContactDisplayName), Worki.Resources.Email.BookingString.BookingMailSubject, WebHelper.RenderEmailToString(MiscHelpers.EmailConstants.ContactDisplayName, teamMailContent)); //send mail to booking member var clientMailContent = string.Format(Worki.Resources.Email.BookingString.CreateBookingClient, Localisation.GetOfferType(offer.Type), formData.MemberBooking.GetStartDate(), formData.MemberBooking.GetEndDate(), locName, offer.Localisation.Adress); var clientMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member.Email, member.MemberMainData.FirstName), Worki.Resources.Email.BookingString.CreateBookingClientSubject, WebHelper.RenderEmailToString(member.MemberMainData.FirstName, clientMailContent)); //send mail to localisation member var urlHelp = new UrlHelper(ControllerContext.RequestContext); var ownerUrl = urlHelp.ActionAbsolute(MVC.Backoffice.Home.Booking()); TagBuilder ownerLink = new TagBuilder("a"); ownerLink.MergeAttribute("href", ownerUrl); ownerLink.InnerHtml = Worki.Resources.Views.Account.AccountString.OwnerSpace; var ownerMailContent = string.Format(Worki.Resources.Email.BookingString.BookingOwnerBody, Localisation.GetOfferType(offer.Type), locName, offer.Localisation.Adress, ownerLink); var ownerMail = _EmailService.PrepareMessageFromDefault(new MailAddress(offer.Localisation.Member.Email, offer.Localisation.Member.MemberMainData.FirstName), string.Format(Worki.Resources.Email.BookingString.BookingOwnerSubject, locName), WebHelper.RenderEmailToString(offer.Localisation.Member.MemberMainData.FirstName, ownerMailContent)); context.Commit(); if (sendNewAccountMail) { _EmailService.Deliver(newMemberMail); } _EmailService.Deliver(clientMail); _EmailService.Deliver(teamMail); _EmailService.Deliver(ownerMail); } catch (Exception ex) { _Logger.Error(ex.Message); context.Complete(); throw ex; } TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Booking.BookingString.Confirmed; return Redirect(offer.Localisation.GetDetailFullUrl(Url)); } catch (Exception ex) { _Logger.Error("Create", ex); ModelState.AddModelError("", ex.Message); } } formData.Periods = new SelectList(Offer.GetPaymentPeriodTypes(offer.GetPricePeriods()), "Key", "Value"); formData.BookingOffer = offer; return View(formData); }
public virtual ActionResult CreateBooking(int id) { var memberId = WebHelper.GetIdentityId(User.Identity); var context = ModelFactory.GetUnitOfWork(); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); var oRepo = ModelFactory.GetRepository<IOfferRepository>(context); var offer = oRepo.Get(id); var member = mRepo.Get(memberId); var formModel = new MemberBookingFormViewModel(member, offer); return PartialView(MVC.Widget.Localisation.Views._CreateBooking, formModel); }