public virtual ActionResult Register(MemberApiModel formData)
        {
            if (ModelState.IsValid)
            {
                var context = ModelFactory.GetUnitOfWork();
                var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
                var sendNewAccountMailPass = false;
                var sendNewAccountMail = false;
                try
                {
                    int memberId;

                    var memberData = new MemberMainData
                    {
                        FirstName = formData.FirstName,
                        LastName = formData.LastName,
                        PhoneNumber = formData.PhoneNumber
                    };
                    if (formData.FacebookId != 0)
                    {
                        memberData.Avatar = this.UploadFile(string.Format(MiscHelpers.FaceBookConstants.FacebookProfilePictureUrlPattern, formData.FacebookId), MiscHelpers.ImageSize.MemberAvatar, Member.AvatarFolder);
                    }
                    if (formData.BirthDate > DateTime.MinValue)
                    {
                        memberData.BirthDate = formData.BirthDate;
                    }
                    if (!string.IsNullOrEmpty(formData.FacebookLink))
                    {
                        memberData.Facebook = formData.FacebookLink;
                    }
                    if (!string.IsNullOrEmpty(formData.PhoneNumber))
                    {
                        memberData.PhoneNumber = formData.PhoneNumber;
                    }

                    if (string.IsNullOrEmpty(formData.Password))
                    {
                        sendNewAccountMailPass = _MembershipService.TryCreateAccount(formData.Email, memberData, out memberId);
                    }
                    else
                    {
                        sendNewAccountMail = _MembershipService.TryCreateAccount(formData.Email, formData.Password, memberData, out memberId);
                    }
                    var member = mRepo.Get(memberId);

                    try
                    {
                        object newMemberMail = null;
                        if (sendNewAccountMailPass)
                        {
                            var urlHelper = new UrlHelper(ControllerContext.RequestContext);

                            var newMemberMailContent = string.Format(Worki.Resources.Email.FacebookRegistration.Content,
                                                                    urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit()),
                                                                    member.Email,
                                                                    _MembershipService.GetPassword(member.Email, null));

                            newMemberMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member.Email, member.MemberMainData.FirstName),
                                Worki.Resources.Email.Activation.ActivationSubject,
                                WebHelper.RenderEmailToString(member.MemberMainData.FirstName, newMemberMailContent));

                        }
                        if (sendNewAccountMail)
                        {
                            var urlHelper = new UrlHelper(ControllerContext.RequestContext);

                            var newMemberMailContent = string.Format(Worki.Resources.Email.FacebookRegistration.ContentWithoutPass,
                                                                    urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit()));

                            newMemberMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member.Email, member.MemberMainData.FirstName),
                                Worki.Resources.Email.Activation.ActivationSubject,
                                WebHelper.RenderEmailToString(member.MemberMainData.FirstName, newMemberMailContent));
                        }
                        context.Commit();

                        if (sendNewAccountMail || sendNewAccountMailPass)
                        {
                            _EmailService.Deliver(newMemberMail);
                        }

                        return new ObjectResult<AuthJson>(ModelHelper.GetAuthData(_MembershipService, formData.Email));
                    }
                    catch (Exception ex)
                    {
                        _Logger.Error(ex.Message);
                        context.Complete();
                        throw ex;
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    return new ObjectResult<AuthJson>(null, 400, dbEx.GetErrors());
                }
                catch (Exception ex)
                {
                    _Logger.Error("Create", ex);
                    ModelState.AddModelError("", ex.Message);
                    return new ObjectResult<AuthJson>(null, 400, ex.Message);
                }
            }
            else
            {
                return new ObjectResult<AuthJson>(null, 400, ModelState.GetErrors());
            }
        }
        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 AddOwnerPlace(OwnerLocalisationModel model)
        {
            var context = ModelFactory.GetUnitOfWork();
            var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
            var lRepo = ModelFactory.GetRepository<ILocalisationRepository>(context);

            if (ModelState.IsValid)
            {
                MemberMainData maindata = new MemberMainData();
                maindata.FirstName = model.Firstname;
                maindata.LastName = model.Name;
                maindata.PhoneNumber = model.PhoneNumber;

                try
                {
                    var loc = lRepo.Get(model.LocalisationId);
                    if (loc == null)
                    {
                        throw new Exception(Worki.Resources.Models.Localisation.Localisation.LocalisationError);
                    }
                    if (loc.OwnerID != 1)
                    {
                        throw new Exception(Worki.Resources.Models.Localisation.Localisation.OwnerAllreadyExist);
                    }

                    int memberId;
                    bool sendNewAccountMail = _MembershipService.TryCreateAccount(model.Email.ToString(), maindata, out memberId, false);

                    if (memberId == 0)
                    {
                        throw new Exception("Utilisateur non crée");
                    }

                    var member = mRepo.Get(memberId);
                    member.MemberMainData.BOStatus = (int)eBOStatus.Done;
                    Roles.AddUserToRole(member.Username, MiscHelpers.BackOfficeConstants.BackOfficeRole);
                    loc.OwnerID = memberId;
                    context.Commit();

                    if (sendNewAccountMail)
                    {
                        var urlHelper = new UrlHelper(ControllerContext.RequestContext);
                        var activationLink = urlHelper.ActionAbsolute(MVC.Account.Activate(member.Email, member.EmailKey));
                        TagBuilder link = new TagBuilder("a");
                        link.MergeAttribute("href", activationLink);
                        link.InnerHtml = activationLink;

                        var ownerMailContent = string.Format(Worki.Resources.Email.Common.AdminOwnershipAndAccount,
                                                            loc.Name,
                                                            activationLink.ToString(),
                                                            loc.GetDetailFullUrl(Url),
                                                            model.Email,
                                                            _MembershipService.GetPassword(model.Email, null));

                        var ownerMail = _EmailService.PrepareMessageFromDefault(new MailAddress(model.Email, model.Firstname),
                              string.Format(Worki.Resources.Email.Common.OwnershipSubject, loc.Name),
                              WebHelper.RenderEmailToString(model.Firstname, ownerMailContent));

                        _EmailService.Deliver(ownerMail);
                    }
                    else
                    {
                        var urlHelper = new UrlHelper(ControllerContext.RequestContext);
                        var boLink = urlHelper.ActionAbsolute(MVC.Backoffice.Localisation.Index(loc.ID));
                        TagBuilder link = new TagBuilder("a");
                        link.MergeAttribute("href", boLink);
                        link.InnerHtml = Worki.Resources.Views.Account.AccountString.OwnerSpace;

                        var ownerMailContent = string.Format(Worki.Resources.Email.Common.AdminOwnership,
                                                            loc.Name,
                                                            boLink.ToString());

                        var ownerMail = _EmailService.PrepareMessageFromDefault(new MailAddress(model.Email, model.Firstname),
                              string.Format(Worki.Resources.Email.Common.OwnershipSubject, loc.Name),
                              WebHelper.RenderEmailToString(model.Firstname, ownerMailContent));

                        _EmailService.Deliver(ownerMail);
                    }

                    return RedirectToAction(MVC.Admin.Member.IndexOwner());
                }
                catch (Exception ex)
                {
                    _Logger.Error("", ex);
                    ModelState.AddModelError("", ex.Message);
                    context.Complete();
                }
            }

            return View(model);
        }
        public virtual ActionResult FacebookOAuth(string code, string state)
        {
            FacebookOAuthResult oauthResult;
            if (FacebookOAuthResult.TryParse(Request.Url, out oauthResult))
            {
                if (oauthResult.IsSuccess)
                {
                    string redirectUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Url.Action(this.FacebookOAuth());

                    var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
                    oAuthClient.RedirectUri = new Uri(redirectUrl);
                    dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code);
                    string accessToken = tokenResult.access_token;

                    //DateTime expiresOn = DateTime.MaxValue;

                    //if (tokenResult.ContainsKey("expires"))
                    //{
                    //    DateTimeConvertor.FromUnixTime(tokenResult.expires);
                    //}

                    FacebookClient fbClient = new FacebookClient(accessToken);
                    dynamic me = fbClient.Get("me?fields=id,name,email,first_name,last_name,link,birthday");
                    long facebookId = Convert.ToInt64(me.id);
                    string faceBookEmailAddress = ((string)me.email).ToString();
                    string faceBookFirstName = ((string)me.first_name).ToString();
                    string faceBookLastName = ((string)me.last_name).ToString();
                    string faceBookLink = ((string)me.link).ToString();
                    var facebookBirthday = DateTime.Parse((string)me.birthday, new System.Globalization.CultureInfo("en"));

                    var context = ModelFactory.GetUnitOfWork();
                    var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
                    var member = mRepo.GetMember(faceBookEmailAddress);

                    if (member == null)
                    {
                        bool created = false;
                        int memberId = 0;
                        try
                        {
                            var uploadedFileName = this.UploadFile(string.Format(MiscHelpers.FaceBookConstants.FacebookProfilePictureUrlPattern, facebookId), MiscHelpers.ImageSize.MemberAvatar, Member.AvatarFolder);
                            var memberData = new MemberMainData
                            {
                                Avatar = uploadedFileName,
                                Facebook = faceBookLink,//string.Format(MiscHelpers.FaceBookConstants.FacebookProfileViewPattern, facebookId, facebookId),
                                FirstName = faceBookFirstName,
                                LastName = faceBookLastName,
                                BirthDate = facebookBirthday
                            };
                            created = _MembershipService.TryCreateAccount(faceBookEmailAddress, memberData, out memberId);
                        }
                        catch (Exception ex)
                        {
                            _Logger.Error(ex.Message);
                        }

                        if (created)
                        {
                            context = ModelFactory.GetUnitOfWork();
                            mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
                            member = mRepo.Get(memberId);
                            var urlHelper = new UrlHelper(ControllerContext.RequestContext);

                            // Send mail
                            try
                            {
                                var facebookMailContent = string.Format(Worki.Resources.Email.FacebookRegistration.Content,
                                                                    urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit()),
                                                                    member.Email,
                                                                    _MembershipService.GetPassword(member.Email, null));

                                var facebookMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member.Email, member.MemberMainData.FirstName),
                                    Worki.Resources.Email.Activation.ActivationSubject,
                                    WebHelper.RenderEmailToString(member.MemberMainData.FirstName, facebookMailContent));

                                _EmailService.Deliver(facebookMail);
                            }
                            catch (Exception ex)
                            {
                                _Logger.Error(ex.Message);
                            }

                            TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Account.InscriptionString.RegisterEworky;
                        }
                        else
                        {
                            return RedirectToAction(MVC.Home.Index());
                        }
                    }

                    var userData = member.GetUserData();
                    _FormsService.SignIn(member.Email, userData, /*model.RememberMe*/true, ControllerContext.HttpContext.Response);

                    if (Url.IsLocalUrl(state))
                    {
                        return Redirect(state);
                    }
                    else
                    {
                        return RedirectToAction(MVC.Home.Index());
                    }
                }
            }
            return RedirectToAction(MVC.Home.Index());
        }
        /// <summary>
        /// Try to create an account for the given mail and data, already activated
        /// if account aleady exists, do nothing
        /// </summary>
        /// <param name="email">email of the account to create</param>
        /// <param name="memberData">member data of the account</param>
        /// <param name="memberId">filled by the fectched account</param>
        /// <returns>true if account created</returns>
        bool TryCreateAccount(string email, string password, bool dummyPassword, MemberMainData memberData, out int memberId, bool forceActivation)
        {
            //check if email match an accounte
            var createAccountContext = ModelFactory.GetUnitOfWork();
            var createAccountmRepo = ModelFactory.GetRepository<IMemberRepository>(createAccountContext);
            try
            {
                var member = createAccountmRepo.GetMember(email);
                if (member != null)
                {
                    memberId = member.MemberId;
                    return false;
                }
                else
                {
                    //if not create an account from memberdata
                    var status = CreateUser(email, password, email, true);
                    if (status != System.Web.Security.MembershipCreateStatus.Success)
                    {
                        var error = AccountValidation.ErrorCodeToString(status);
                        throw new Exception(error);
                    }

                    var created = createAccountmRepo.GetMember(email);
                    created.MemberMainData = memberData;
                    createAccountContext.Commit();

                    //try reset password if not dummy
                    if (dummyPassword && !ResetPassword(email))
                    {
                        throw new Exception("ResetPassword failed");
                    }

                    var unactivateAccountContext = ModelFactory.GetUnitOfWork();
                    try
                    {
                        var unactivateAccountRepo = ModelFactory.GetRepository<IMemberRepository>(unactivateAccountContext);
                        var toUnactiavte = unactivateAccountRepo.GetMember(email);
                        toUnactiavte.IsApproved = forceActivation;
                        unactivateAccountContext.Commit();
                    }
                    catch (Exception ex)
                    {
                        unactivateAccountContext.Complete();
                        throw ex;
                    }

                    memberId = created.MemberId;
                    return true;
                }
            }
            catch (Exception ex)
            {
                createAccountContext.Complete();
                throw ex;
            }
        }
 /// <summary>
 /// Try to create an account for the given mail and data, already activated
 /// if account aleady exists, do nothing
 /// </summary>
 /// <param name="email">email of the account to create</param>
 /// <param name="password">account password</param>
 /// <param name="memberData">member data of the account</param>
 /// <param name="memberId">filled by the fectched account</param>
 /// <returns>true if account created</returns>
 public bool TryCreateAccount(string email, string password, MemberMainData memberData, out int memberId, bool forceActivation = true)
 {
     return TryCreateAccount(email, password, false, memberData, out  memberId, forceActivation);
 }
 /// <summary>
 /// Try to create an account for the given mail and data, already activated
 /// if account aleady exists, do nothing
 /// </summary>
 /// <param name="email">email of the account to create</param>
 /// <param name="memberData">member data of the account</param>
 /// <param name="memberId">filled by the fectched account</param>
 /// <returns>true if account created</returns>
 public bool TryCreateAccount(string email, MemberMainData memberData, out int memberId, bool forceActivation = true)
 {
     return TryCreateAccount(email, MiscHelpers.AdminConstants.DummyPassword, true, memberData, out  memberId, forceActivation);
 }
Beispiel #8
0
 public RegisterModel()
 {
     CivilitySelectTypes = new SelectList(MemberMainData.GetCivilityTypes(), "Key", "Value", CivilityType.Mr);
     ProfileSelectTypes = new SelectList(MemberMainData.GetProfileTypes(), "Key", "Value", ProfileType.LocalisationOwner);
     MemberMainData = new MemberMainData();
     AcceptCGU = true;
 }
        /// <summary>
        /// private method to create quoation and send corresponding mails
        /// </summary>
        /// <param name="memberId">the client</param>
        /// <param name="offerId">the offer</param>
        /// <param name="formData">quotation data</param>
        void CreateQuotation(int memberId, int offerId, MemberQuotationFormViewModel formData)
        {
            var context = ModelFactory.GetUnitOfWork();
            var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
            var oRepo = ModelFactory.GetRepository<IOfferRepository>(context);
            var lRepo = ModelFactory.GetRepository<ILocalisationRepository>(context);

            var member = mRepo.Get(memberId);
            var offer = oRepo.Get(offerId);
            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);
                var localisation = lRepo.Get(offer.LocalisationId);
                var hasOwner = localisation.HasOwner();

                if (hasOwner)
                {
                    formData.MemberQuotation.MemberId = memberId;
                    formData.MemberQuotation.OfferId = offerId;
                    formData.MemberQuotation.StatusId = (localisation.DirectlyReceiveQuotation == true) ? (int)MemberQuotation.Status.Unknown : (int)MemberQuotation.Status.Pending;
                    member.MemberQuotations.Add(formData.MemberQuotation);

                    formData.MemberQuotation.MemberQuotationLogs.Add(new MemberQuotationLog
                    {
                        CreatedDate = DateTime.UtcNow,
                        Event = "Quotation Created",
                        EventType = (int)MemberQuotationLog.QuotationEvent.Creation,
                        LoggerId = memberId
                    });
                }
                //set phone number to the one from form
                member.MemberMainData.PhoneNumber = formData.PhoneNumber;

                dynamic newMemberMail = null;
                if (sendNewAccountMail)
                {
                    var urlHelper = new UrlHelper(ControllerContext.RequestContext);
                    var editpasswordUrl = urlHelper.ActionAbsolute(MVC.Dashboard.Profil.ChangePassword());
                    TagBuilder editpasswordLink = new TagBuilder("a");
                    editpasswordLink.MergeAttribute("href", editpasswordUrl);
                    editpasswordLink.InnerHtml = Worki.Resources.Views.Account.AccountString.ChangeMyPassword;
                    var editprofilUrl = urlHelper.ActionAbsolute(MVC.Dashboard.Profil.Edit());
                    TagBuilder editprofilLink = new TagBuilder("a");
                    editprofilLink.MergeAttribute("href", editprofilUrl);
                    editprofilLink.InnerHtml = Worki.Resources.Views.Account.AccountString.EditMyProfile;

                    var newMemberMailContent = string.Format(Worki.Resources.Email.BookingString.QuotationNewMemberBody,
                                                            Localisation.GetOfferType(offer.Type), //0
                                                            offer.Localisation.Name, //1
                                                            offer.Localisation.Adress, //2
                                                            formData.Email, //3
                                                            _MembershipService.GetPassword(formData.Email, null), //4
                                                            editpasswordLink, //5
                                                            editprofilLink); //6;

                    newMemberMail = _EmailService.PrepareMessageFromDefault(new MailAddress(formData.Email, formData.FirstName),
                        Worki.Resources.Email.BookingString.QuotationNewMemberSubject,
                        WebHelper.RenderEmailToString(formData.FirstName, newMemberMailContent));
                }

                //send mail to team
                var teamMailContent = string.Format(Worki.Resources.Email.BookingString.QuotationMailBody,
                                                 string.Format("{0} {1}", member.MemberMainData.FirstName, member.MemberMainData.LastName), //0
                                                 formData.PhoneNumber, //1
                                                 member.Email, //2
                                                 locName, //3
                                                 Localisation.GetOfferType(offer.Type), //4
                                                 formData.MemberQuotation.Message, //5
                                                 locUrl); //6

                var teamMail = _EmailService.PrepareMessageFromDefault(new MailAddress(MiscHelpers.EmailConstants.BookingMail, MiscHelpers.EmailConstants.ContactDisplayName),
                    hasOwner ? Worki.Resources.Email.BookingString.QuotationMailSubject : Worki.Resources.Email.BookingString.QuotationMailSubject + " (sans gérant)",
                    WebHelper.RenderEmailToString(MiscHelpers.EmailConstants.ContactDisplayName, teamMailContent));

                //send mail to quoation client
                var clientMailContent = string.Format(Worki.Resources.Email.BookingString.CreateQuotationClient,
                                                 Localisation.GetOfferType(offer.Type), //0
                                                 locName, //1
                                                 offer.Localisation.Adress); //2

                var clientMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member.Email, member.MemberMainData.FirstName),
                     Worki.Resources.Email.BookingString.CreateQuotationClientSubject,
                    WebHelper.RenderEmailToString(member.MemberMainData.FirstName, clientMailContent));

                context.Commit();

                if (hasOwner && formData.MemberQuotation.StatusId == (int)MemberQuotation.Status.Unknown)
                {
                    //we set the information for the mail after commit in order to get the id of the MemberQuotation that have been inserted
                    var context2 = ModelFactory.GetUnitOfWork();

                    var oRepo2 = ModelFactory.GetRepository<IOfferRepository>(context2);
                    var lRepo2 = ModelFactory.GetRepository<ILocalisationRepository>(context2);
                    var mRepo2 = ModelFactory.GetRepository<IMemberRepository>(context2);

                    var offer2 = oRepo2.Get(offerId);
                    var localisation2 = lRepo2.Get(offer.LocalisationId);
                    var member2 = mRepo2.Get(localisation2.OwnerID);

                    var urlHelp = new UrlHelper(ControllerContext.RequestContext);
                    //we get the ownerUrl from the id of the created MemberQuotation
                    var ownerUrl = urlHelp.ActionAbsolute(MVC.Backoffice.Localisation.QuotationDetail(formData.MemberQuotation.Id));
                    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.CreateQuotationOwner,
                                                    Localisation.GetOfferType(offer.Type),
                                                    localisation2.Name,
                                                    localisation2.Adress,
                                                    ownerLink);

                    var ownerMail = _EmailService.PrepareMessageFromDefault(new MailAddress(member2.Email, localisation2.Member.MemberMainData.FirstName),
                          string.Format(Worki.Resources.Email.BookingString.CreateQuotationOwnerSubject, localisation2.Name),
                          WebHelper.RenderEmailToString(member2.Email, ownerMailContent));

                    _EmailService.Deliver(ownerMail);
                }
                if (sendNewAccountMail)
                {
                    _EmailService.Deliver(newMemberMail);
                }
                _EmailService.Deliver(clientMail);
                _EmailService.Deliver(teamMail);
            }
            catch (Exception ex)
            {
                _Logger.Error(ex.Message);
                context.Complete();
                throw ex;
            }
        }