/// <summary> /// Gets the modules. /// </summary> /// <param name="poeid">The poeid.</param> /// <returns></returns> public void SignUp(SignupRequest sr) { //New user int userid = 0; var user = sr.User; string salt = CreateSalt(); string encPassword = CreatePasswordHash(user.Password + salt); using (var context = DataContextFactory.GetIntelliSetDataContext()) { if (sr.Mode == 0) { var resultuser = context.RegisterUser(user.FirstName + " " + user.LastName, user.Password, encPassword, salt, user.FirstName, user.LastName, user.EmailAddress, user.CompanyName, Convert.ToInt32(user.Country.Id), user.Photo, user.YammerToken).FirstOrDefault(); if (resultuser != null) { userid = resultuser.UserId.GetValueOrDefault(); } sr.User.UserId = userid; SendWelcomeEmail(user.FirstName + " " + user.LastName, user.EmailAddress); } int subscriptionId = 0; var resultsub = context.CreateSubscription(user.EmailAddress, sr.Netwrok.NetworkName, 1, 1, sr.Netwrok.Plan).ToList(); if (resultsub.Count > 0) { subscriptionId = resultsub[0].SubscriptionID.GetValueOrDefault(0); } if (userid != 0) { //subscriptionId = (from c in resultsub let subscriptionID = c.SubscriptionID where subscriptionID != null select subscriptionID.Value).FirstOrDefault(); context.UserSubscribtions(subscriptionId, userid, DateTime.Now, 1, 10, 120); } sr.Netwrok.Subscriptionid = subscriptionId; int salesOrderId = 0; if (sr.Payment != null) { var resultPayment = context.InsertPayment(subscriptionId, sr.Payment.Amount, sr.Payment.Response, sr.Payment.ResponseId); if (resultPayment != null) { salesOrderId = resultPayment.FirstOrDefault().SalesOrderId.GetValueOrDefault(); } } //Insert SubscribedPoes var common = new Common.Common(); var subscriptedPoes = common.GetSubscribedPoes(subscriptionId); List <Util.Domain.POE> newlyAddedPoes = sr.Poes; if (sr.Poes != null) { foreach (var poe in subscriptedPoes) { newlyAddedPoes.RemoveAll(a => a.POEId == poe.POEId); } foreach (Util.Domain.POE poe in sr.Poes) { if (sr.Payment != null) { context.InsertSalesOrderItem(salesOrderId, 1, poe.POEId, poe.Name, 20.00m); } float poecost = 0; if (sr.Members != null) { poecost = sr.Members[0].PoeAmount; } context.InsertSubscribedPoes(poe.POEId, subscriptionId, poecost); } } if (newlyAddedPoes != null) { foreach (var poe in newlyAddedPoes) { SendAddPoeNotificationEmail(user.FirstName + " " + user.LastName, user.EmailAddress, poe.Name); } } if (sr.Members != null) { foreach (UserPOEMapping member in sr.Members) { int parentMappingid = 0; int childMappingId = 0; int peerParentMappingid = 0; int peerchildMappingId = 0; int memberid = 0; string salttemp = CreateSalt(); string encPasswordtemp = CreatePasswordHash("Pass@123" + salttemp); var resultmembers = context.RegisterUser(member.User.FirstName + " " + member.User.LastName, "Pass@123", encPasswordtemp, salttemp, member.User.FirstName, member.User.LastName, member.User.EmailAddress, user.CompanyName, Convert.ToInt32(user.Country.Id), null, member.User.YammerToken).FirstOrDefault(); if (member.Designation.Level != (int)NetworkUserFilterType.Customer) { SendInviteEmail( sr.User.FirstName + " " + sr.User.LastName, member.User.FirstName + " " + member.User.LastName, sr.User.EmailAddress, member.User.EmailAddress, subscriptionId); } if (resultmembers != null) { memberid = resultmembers.UserId.GetValueOrDefault(); context.UserSubscribtions(subscriptionId, memberid, DateTime.Now, 1, member.Designation.Level, member.UserAmount); } member.User.UserId = memberid; if (member.POE.POEId != 0) { switch (member.Designation.Level) { case (int)NetworkUserFilterType.TeamMember: parentMappingid = InsertPoeMapping(user.UserId, member.POE.POEId, 2, "Manager", sr.Netwrok.Subscriptionid); childMappingId = InsertPoeMapping(member.User.UserId, member.POE.POEId, member.Designation.Level, member.Designation.Name, sr.Netwrok.Subscriptionid); break; case (int)NetworkUserFilterType.Manager: parentMappingid = InsertPoeMapping(member.User.UserId, member.POE.POEId, member.Designation.Level, member.Designation.Name, sr.Netwrok.Subscriptionid); childMappingId = InsertPoeMapping(user.UserId, member.POE.POEId, 1, "Team Member", sr.Netwrok.Subscriptionid); break; case (int)NetworkUserFilterType.SkipLevelManager: parentMappingid = InsertPoeMapping(member.User.UserId, member.POE.POEId, member.Designation.Level, member.Designation.Name, sr.Netwrok.Subscriptionid); childMappingId = InsertPoeMapping(user.UserId, member.POE.POEId, 1, "Team Member", sr.Netwrok.Subscriptionid); break; case (int)NetworkUserFilterType.Customer: parentMappingid = InsertPoeMapping(member.User.UserId, member.POE.POEId, member.Designation.Level, member.Designation.Name, sr.Netwrok.Subscriptionid); childMappingId = InsertPoeMapping(user.UserId, member.POE.POEId, 1, "Team Member", sr.Netwrok.Subscriptionid); break; case (int)NetworkUserFilterType.PeerManager: parentMappingid = InsertPoeMapping(member.User.UserId, member.POE.POEId, (int)NetworkUserFilterType.PeerManager, member.Designation.Name, sr.Netwrok.Subscriptionid); childMappingId = InsertPoeMapping(user.UserId, member.POE.POEId, (int)NetworkUserFilterType.PeerTeam, "Peer Team Member", sr.Netwrok.Subscriptionid); peerParentMappingid = InsertPoeMapping(user.UserId, member.POE.POEId, (int)NetworkUserFilterType.PeerManager, "Peer Manager", sr.Netwrok.Subscriptionid); peerchildMappingId = InsertPoeMapping(member.User.UserId, member.POE.POEId, (int)NetworkUserFilterType.PeerTeam, member.Designation.Name, sr.Netwrok.Subscriptionid); break; } } if (parentMappingid != 0 && childMappingId != 0) { InsertNetworkUsers(parentMappingid, childMappingId, sr.Netwrok.NetworkName, sr.Netwrok.Subscriptionid); } if (peerParentMappingid != 0 && peerchildMappingId != 0) { InsertNetworkUsers(peerParentMappingid, peerchildMappingId, sr.Netwrok.NetworkName, sr.Netwrok.Subscriptionid); } member.ParentMappingId = parentMappingid; member.ChildMappingId = childMappingId; member.PeerParentMappingId = peerParentMappingid; member.PeerChildMappingId = peerchildMappingId; //insert sales order if (sr.Payment != null) { context.InsertSalesOrderItem(salesOrderId, 2, memberid, member.User.EmailAddress, 5.00m); } } } } }