public ActionResult Create(OrganizationView organization) { Logger.Debug("Inside Organization Controller- Create HttpPost"); try { if (ModelState.IsValid) { if (_IOrganizationRepository.GetOrganizationByID(organization.OrganizationGUID) == null) { Organization Organization = new Organization(); Organization.OrganizationFullName = organization.OrganizationFullName; Organization.OrganizationName = organization.OrganizationFullName.Trim(); Organization.OrganizationGUID = Guid.NewGuid(); Organization.Website = organization.Website; Organization.Phone = organization.Phone; Organization.AddressLine1 = organization.AddressLine1; Organization.AddressLine2 = organization.AddressLine2; Organization.City = organization.City; Organization.Country = organization.Country; Organization.ZipCode = organization.ZipCode; LatLong latLong = new LatLong(); latLong = GetLatLngCode(Organization.AddressLine1, Organization.AddressLine2, Organization.City, Organization.State, Organization.Country, Organization.ZipCode); Organization.TimeZone = Convert.ToDouble(getTimeZone(latLong.Latitude, latLong.Longitude)); Organization.Latitude = latLong.Latitude; Organization.Longitude = latLong.Longitude; Organization.EmailID = organization.EmailID; Organization.State = organization.State; Organization.IsActive = false; Organization.IsDeleted = false; Organization.AllowContractors = true; Organization.ImageURL = organization.ImageURL; Organization.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) Organization.CreateBy = new Guid(Session["UserGUID"].ToString()); Organization.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) Organization.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); //Group Group = new Group(); //Group.GroupGUID = Guid.NewGuid(); //Group.Name = "Default"; //Group.Description = "Default"; //Group.OrganizationGUID = Organization.OrganizationGUID; //Group.IsDefault = false; Region Region = new Region(); Region.RegionGUID = Guid.NewGuid(); Region.Name = "Default"; Region.Description = "Default"; if (Organization.OrganizationGUID != Guid.Empty) { Region.OrganizationGUID = Organization.OrganizationGUID; } else { Region.OrganizationGUID = null; } Region.IsDefault = false; Territory Territory = new Territory(); Territory.TerritoryGUID = Guid.NewGuid(); if (Territory.RegionGUID != Guid.Empty) { Territory.RegionGUID = Territory.RegionGUID; } else { Territory.RegionGUID = null; } Territory.Name = "Default"; Territory.Description = "Default"; if (Organization.OrganizationGUID != Guid.Empty) { Territory.OrganizationGUID = Organization.OrganizationGUID; } else { Territory.OrganizationGUID = null; } Territory.IsDefault = false; GlobalUser globalUser = new GlobalUser(); globalUser.UserGUID = Guid.NewGuid(); globalUser.USERID = organization.UserID; globalUser.UserName = organization.UserName; globalUser.Password = _IUserRepository.EncodeTo64(organization.Password); globalUser.IsActive = true; globalUser.IsDelete = false; globalUser.Latitude = latLong.Latitude; globalUser.Longitude = latLong.Longitude; globalUser.Role_Id = _IGlobalUserRepository.GetOrganizationAdminRoleID(); globalUser.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.CreateBy = new Guid(Session["UserGUID"].ToString()); globalUser.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); UserProfile userprofile = new UserProfile(); userprofile.ProfileGUID = Guid.NewGuid(); userprofile.UserGUID = globalUser.UserGUID; userprofile.CompanyName = Organization.OrganizationFullName; userprofile.FirstName = organization.FirstName; userprofile.LastName = organization.LastName; userprofile.MobilePhone = ""; userprofile.BusinessPhone = organization.Phone; userprofile.HomePhone = ""; userprofile.EmailID = organization.EmailID; userprofile.AddressLine1 = organization.AddressLine1; userprofile.AddressLine2 = organization.AddressLine2; userprofile.City = organization.City; userprofile.State = organization.State; userprofile.Country = organization.Country; userprofile.Latitude = latLong.Latitude; userprofile.Longitude = latLong.Longitude; userprofile.ZipCode = organization.ZipCode; userprofile.IsDeleted = false; userprofile.PicFileURL = Organization.ImageURL; userprofile.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) userprofile.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); userprofile.CompanyName = Organization.OrganizationName; AspNetUser aspnetuser = new AspNetUser(); aspnetuser.Id = globalUser.UserGUID.ToString(); aspnetuser.UserName = organization.UserName; aspnetuser.FirstName = organization.FirstName; aspnetuser.LastName = organization.LastName; aspnetuser.PasswordHash = _IUserRepository.EncodeTo64(organization.Password); aspnetuser.PhoneNumber = organization.Phone; aspnetuser.EmailID = organization.EmailID; if (Organization.OrganizationGUID != Guid.Empty) { aspnetuser.OrganizationGUID = Organization.OrganizationGUID; } else { aspnetuser.OrganizationGUID = null; } aspnetuser.SecurityStamp = ""; aspnetuser.Discriminator = ""; OrganizationSubscription organizationSubscription = new OrganizationSubscription(); organizationSubscription.OrganizationSubscriptionGUID = Guid.NewGuid(); organizationSubscription.OrganizationGUID = Organization.OrganizationGUID; organizationSubscription.IsActive = true; organizationSubscription.Version = 1; organizationSubscription.SubscriptionPurchased = 100; organizationSubscription.SubscriptionConsumed = 1; organizationSubscription.StartDate = DateTime.UtcNow; organizationSubscription.ExpiryDate = DateTime.UtcNow.AddDays(30); organizationSubscription.CreatedDate = DateTime.UtcNow; UserSubscription userSubscription = new UserSubscription(); userSubscription.UserSubscriptionGUID = Guid.NewGuid(); userSubscription.UserGUID = globalUser.UserGUID; if (organizationSubscription.OrganizationSubscriptionGUID != Guid.Empty) { userSubscription.OrganizationSubscriptionGUID = organizationSubscription.OrganizationSubscriptionGUID; } else { userSubscription.OrganizationSubscriptionGUID = null; } userSubscription.IsActive = true; userSubscription.CreatedDate = DateTime.UtcNow; Market Market = new Market(); Market.MarketGUID = Guid.NewGuid(); Market.IsDefault = true; if (globalUser.UserGUID != Guid.Empty) { Market.UserGUID = globalUser.UserGUID; } else { Market.UserGUID = null; } Market.EntityType = 0; if (Organization.OrganizationGUID != Guid.Empty) { Market.OrganizationGUID = Organization.OrganizationGUID; } else { Market.OrganizationGUID = null; } if (Organization.OrganizationGUID != Guid.Empty) { Market.OwnerGUID = Organization.OrganizationGUID; } else { Market.OwnerGUID = null; } Market.MarketName = Organization.OrganizationFullName; if (Region.RegionGUID != Guid.Empty) { Market.RegionGUID = Region.RegionGUID; } else { Market.RegionGUID = null; } if (Territory.TerritoryGUID != Guid.Empty) { Market.TerritoryGUID = Territory.TerritoryGUID; } else { Market.TerritoryGUID = null; } if (globalUser.UserGUID != Guid.Empty) { Market.PrimaryContactGUID = globalUser.UserGUID; } else { Market.PrimaryContactGUID = null; } Market.FirstName = organization.FirstName; Market.LastName = organization.LastName; Market.MobilePhone = ""; Market.MarketPhone = organization.Phone; Market.HomePhone = ""; Market.Emails = organization.EmailID; Market.TimeZone = Organization.TimeZone.ToString(); Market.AddressLine1 = organization.AddressLine1; Market.AddressLine2 = organization.AddressLine2; Market.City = organization.City; Market.State = organization.State; Market.Country = organization.Country; Market.ZipCode = organization.ZipCode; Market.Latitude = latLong.Latitude; Market.Longitude = latLong.Longitude; Market.ImageURL = organization.ImageURL; Market.IsDeleted = false; Market.CreateDate = DateTime.UtcNow; Market.UpdatedDate = DateTime.UtcNow; OrganizationUsersMap organizationUserMap = new OrganizationUsersMap(); organizationUserMap.OrganizationUserMapGUID = Guid.NewGuid(); organizationUserMap.OrganizationGUID = Organization.OrganizationGUID; organizationUserMap.UserGUID = globalUser.UserGUID; organizationUserMap.IsContractor = false; organizationUserMap.IsActive = true; organizationUserMap.Status = 0; if (Region.RegionGUID != Guid.Empty) { organizationUserMap.RegionGUID = Region.RegionGUID; } else { organizationUserMap.RegionGUID = null; } if (Territory.TerritoryGUID != Guid.Empty) { organizationUserMap.TerritoryGUID = Territory.TerritoryGUID; } else { organizationUserMap.TerritoryGUID = null; } organizationUserMap.UserType = "ENT_A"; organizationUserMap.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.CreateBy = new Guid(Session["UserGUID"].ToString()); organizationUserMap.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); int result = _IOrganizationRepository.InsertOrganization(Organization); // int result = _IOrganizationRepository.Save(); if (result > 0) { _IOrganizationSubscriptionRepository.InsertOrganizationSubscription(organizationSubscription); //_IOrganizationSubscriptionRepository.Save(); //_IGroupRepository.InsertGroup(Group); //_IGroupRepository.Save(); _IRegionRepository.InsertRegion(Region); //_IRegionRepository.Save(); _ITerritoryRepository.InsertTerritory(Territory); // _ITerritoryRepository.Save(); int userresult = _IUserRepository.InsertUser(aspnetuser); // int userresult = _IUserRepository.Save(); if (userresult > 0) { int guresult = _IGlobalUserRepository.InsertGlobalUser(globalUser); //int guresult = _IGlobalUserRepository.Save(); if (guresult > 0) { int OrgUserMap = _IOrganizationRepository.InsertOrganizationUserMap(organizationUserMap); //int OrgUserMap = _IOrganizationRepository.Save(); if (OrgUserMap > 0) { int usrresult = _IUserProfileRepository.InsertUserProfile(userprofile); //int usrresult = _IUserProfileRepository.Save(); if (usrresult > 0) { int usubresult = _IUserSubscriptionRepository.InsertUserSubscription(userSubscription); //int usubresult = _IUserSubscriptionRepository.Save(); if (usubresult > 0) { int marketresult = _IMarketRepository.InsertMarket(Market); //int marketresult = _IMarketRepository.Save(); if (marketresult > 0) { if (Session["UserType"] != null && Session["UserType"].ToString() == "WIM_A") { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Created Successfully');</script>"; return RedirectToAction("Index", "Organization"); } else { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Created Successfully');</script>"; return RedirectToAction("../User/Login"); } } else { _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); //_IGroupRepository.DeleteGroup(Group.GroupGUID); //_IGroupRepository.Save(); _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID); //_ITerritoryRepository.Save(); _IRegionRepository.DeleteRegion(Region.RegionGUID); //_IRegionRepository.Save(); _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); //_IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { //_IGroupRepository.DeleteGroup(Group.GroupGUID); //_IGroupRepository.Save(); _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID); //_ITerritoryRepository.Save(); _IRegionRepository.DeleteRegion(Region.RegionGUID); // _IRegionRepository.Save(); _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); //_IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID); //_IOrganizationSubscriptionRepository.Save(); //_IUserSubscriptionRepository.Save(); _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); //_IOrganizationRepository.Save(); } } else { _IOrganizationRepository.DeleteOrganizationUserMap(organizationUserMap.OrganizationUserMapGUID); //_IOrganizationRepository.Save(); _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID); //_ITerritoryRepository.Save(); _IRegionRepository.DeleteRegion(Region.RegionGUID); //_IRegionRepository.Save(); _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); //_IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID); //_IOrganizationSubscriptionRepository.Save(); //_IUserSubscriptionRepository.Save(); _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); //_IOrganizationRepository.Save(); } } else { //_IGroupRepository.DeleteGroup(Group.GroupGUID); //_IGroupRepository.Save(); _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID); //_ITerritoryRepository.Save(); _IRegionRepository.DeleteRegion(Region.RegionGUID); // _IRegionRepository.Save(); _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); // _IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID); //_IOrganizationSubscriptionRepository.Save(); //_IUserSubscriptionRepository.Save(); _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); //_IOrganizationRepository.Save(); } } else { _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); //_IOrganizationRepository.Save(); } } else { _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID); //_IOrganizationSubscriptionRepository.Save(); _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); // _IOrganizationRepository.Save(); } } else { _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID); //_IOrganizationRepository.Save(); } } else { //UserName already exists TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Name is Aleady Exists');</script>"; } } return View(organization); } catch (Exception ex) { Logger.Error(ex.Message); return View(organization); } }
public ActionResult Create(AspUser user, string GroupGUID, string RegionGUID, string TerritoryGUID, string RoleGUID) { Logger.Debug("Inside User Controller- Create HttpPost"); try { if (Session["OrganizationGUID"] != null) { DropdownValues(); ViewBag.OrganizationName = _IOrganizationRepository.GetOrganizationByID(new Guid(Session["OrganizationGUID"].ToString())).OrganizationFullName; if (ModelState.IsValid) { OrganizationSubscription orgSubscription = _IOrganizationSubscriptionRepository.GetOrganizationSubscriptionByOrgID(new Guid(Session["OrganizationGUID"].ToString())); // if (orgSubscription.SubscriptionPurchased > orgSubscription.SubscriptionConsumed) { GlobalUser aspuser = _IUserRepository.GlobalUserLogin(user.UserName, Session["OrganizationGUID"].ToString()); GlobalUser aUser = _IGlobalUserRepository.GetGlobalUserByUserID(user.UserID, Session["OrganizationGUID"].ToString()); if (aspuser == null && aUser == null) { LatLong latLong = new LatLong(); latLong = GetLatLngCode(user.AddressLine1, user.AddressLine2, user.City, user.State, user.Country, user.ZipCode); GlobalUser globalUser = new GlobalUser(); globalUser.UserGUID = Guid.NewGuid(); globalUser.USERID = user.UserID; globalUser.Role_Id = RoleGUID; globalUser.UserName = !string.IsNullOrEmpty(user.UserName) ? user.UserName.Trim() : ""; globalUser.Password = _IUserRepository.EncodeTo64(user.PasswordHash); globalUser.IsActive = true; globalUser.IsDelete = false; globalUser.Latitude = latLong.Latitude; globalUser.Longitude = latLong.Longitude; globalUser.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.CreateBy = new Guid(Session["UserGUID"].ToString()); globalUser.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); OrganizationUsersMap organizationUserMap = new OrganizationUsersMap(); organizationUserMap.OrganizationUserMapGUID = Guid.NewGuid(); organizationUserMap.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); organizationUserMap.UserGUID = globalUser.UserGUID; organizationUserMap.IsContractor = false; organizationUserMap.IsActive = true; organizationUserMap.Status = 0; if (!string.IsNullOrEmpty(RegionGUID) && RegionGUID != Guid.Empty.ToString()) { organizationUserMap.RegionGUID = new Guid(RegionGUID); } else { organizationUserMap.RegionGUID = null; } if (!string.IsNullOrEmpty(TerritoryGUID) && TerritoryGUID != Guid.Empty.ToString()) { organizationUserMap.TerritoryGUID = new Guid(TerritoryGUID); } else { organizationUserMap.TerritoryGUID = null; } organizationUserMap.UserType = "ENT_A"; organizationUserMap.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.CreateBy = new Guid(Session["UserGUID"].ToString()); organizationUserMap.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); UserProfile userprofile = new UserProfile(); userprofile.ProfileGUID = Guid.NewGuid(); userprofile.UserGUID = globalUser.UserGUID; userprofile.CompanyName = _IOrganizationRepository.GetOrganizationByID(new Guid(Session["OrganizationGUID"].ToString())).OrganizationFullName; userprofile.FirstName = !string.IsNullOrEmpty(user.FirstName) ? user.FirstName.Trim() : ""; userprofile.LastName = !string.IsNullOrEmpty(user.LastName) ? user.LastName.Trim() : ""; userprofile.MobilePhone = user.MobilePhone; userprofile.BusinessPhone = user.BusinessPhone; userprofile.HomePhone = user.HomePhone; userprofile.EmailID = !string.IsNullOrEmpty(user.EmailID) ? user.EmailID.Trim() : ""; userprofile.AddressLine1 = user.AddressLine1; userprofile.AddressLine2 = user.AddressLine2; userprofile.City = user.City; userprofile.State = user.State; userprofile.Country = user.Country; userprofile.Latitude = latLong.Latitude; userprofile.Longitude = latLong.Longitude; userprofile.ZipCode = user.ZipCode; userprofile.IsDeleted = false; userprofile.PicFileURL = user.ImageURL; userprofile.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) userprofile.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); AspNetUser aspnetuser = new AspNetUser(); aspnetuser.Id = globalUser.UserGUID.ToString(); aspnetuser.UserName = !string.IsNullOrEmpty(user.UserName) ? user.UserName.Trim() : ""; aspnetuser.FirstName = !string.IsNullOrEmpty(user.FirstName) ? user.FirstName.Trim() : ""; aspnetuser.LastName = !string.IsNullOrEmpty(user.LastName) ? user.LastName.Trim() : ""; aspnetuser.PasswordHash = _IUserRepository.EncodeTo64(user.PasswordHash); aspnetuser.PhoneNumber = user.MobilePhone; aspnetuser.EmailID = !string.IsNullOrEmpty(user.EmailID) ? user.EmailID.Trim() : ""; aspnetuser.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); aspnetuser.SecurityStamp = ""; aspnetuser.Discriminator = ""; UserSubscription userSubscription = new UserSubscription(); if (orgSubscription != null) { userSubscription.UserSubscriptionGUID = Guid.NewGuid(); userSubscription.UserGUID = globalUser.UserGUID; userSubscription.OrganizationSubscriptionGUID = orgSubscription.OrganizationSubscriptionGUID; userSubscription.IsActive = true; userSubscription.CreatedDate = DateTime.UtcNow; } int userresult = _IUserRepository.InsertUser(aspnetuser); //int userresult = _IUserRepository.Save(); if (userresult > 0) { int guresult = _IGlobalUserRepository.InsertGlobalUser(globalUser); //int guresult = _IGlobalUserRepository.Save(); if (guresult > 0) { int usrresult = _IUserProfileRepository.InsertUserProfile(userprofile); //int usrresult = _IUserProfileRepository.Save(); if (usrresult > 0) { int uSubscriptionResult = _IUserSubscriptionRepository.InsertUserSubscription(userSubscription); //int uSubscriptionResult = _IUserSubscriptionRepository.Save(); if (uSubscriptionResult > 0) { int orgusermap = _IOrganizationRepository.InsertOrganizationUserMap(organizationUserMap); //int orgusermap = _IOrganizationRepository.Save(); if (orgusermap > 0) { orgSubscription.SubscriptionConsumed = orgSubscription.SubscriptionConsumed + 1; _IOrganizationSubscriptionRepository.UpdateOrganizationSubscription(orgSubscription); //_IOrganizationSubscriptionRepository.Save(); return RedirectToAction("Index", "MyCompany", new { id = "Users" }); } else { _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); // _IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); } } else { _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); // _IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); } } else { _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else if (aspuser != null) { //UserName already exists for this Organization TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','User Aleady Exists');</script>"; } else if (aUser != null) { //UserID already exists for this Organization TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','UserID is Aleady Exists');</script>"; } } } else { var TerritoryDetails = _ITerritoryRepository.GetTerritoryByRegionGUID(new Guid(RegionGUID)).ToList().OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.TerritoryGUID.ToString(), Text = r.Name }); ViewBag.TerritoryDetails = new SelectList(TerritoryDetails, "Value", "Text"); } return View(user); } else { //TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Session Expired');</script>"; //return RedirectToAction("../User/Login"); return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return View(user); } }
public ActionResult Edit(AspUser user, string GroupGUID, string RegionGUID, string TerritoryGUID, string RoleGUID) { Logger.Debug("Inside User Controller- Edit HttpPost"); try { if (Session["OrganizationGUID"] != null) { DropdownValues(); ViewBag.UserName = user.UserName; string oldpassword = _IUserRepository.DecodeFrom64(_IGlobalUserRepository.GetPassword(new Guid(user.UserGUID))); if (ModelState.IsValid) { LatLong latLong = new LatLong(); latLong = GetLatLngCode(user.AddressLine1, user.AddressLine2, user.City, user.State, user.Country, user.ZipCode); GlobalUser globalUser = new GlobalUser(); globalUser.UserGUID = new Guid(user.UserGUID); globalUser.USERID = !string.IsNullOrEmpty(user.UserID) ? user.UserID.Trim() : ""; globalUser.Role_Id = RoleGUID; globalUser.UserName = !string.IsNullOrEmpty(user.UserName) ? user.UserName.Trim() : ""; globalUser.Password = _IUserRepository.EncodeTo64(user.PasswordHash); globalUser.IsActive = true; globalUser.IsDelete = false; globalUser.Latitude = latLong.Latitude; globalUser.Longitude = latLong.Longitude; globalUser.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); if (_IGlobalUserRepository.GetRole(globalUser.Role_Id).UserType == "ENT_A") { var RoleDetails = _IGlobalUserRepository.GetRoles().ToList().Where(r => r.UserType != "WIM_A" && r.UserType != "IND_C").OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }); ViewBag.RoleDetails = new SelectList(RoleDetails, "Value", "Text"); } else if (_IGlobalUserRepository.GetRole(globalUser.Role_Id).UserType == "WIM_A") { var RoleDetails = _IGlobalUserRepository.GetRoles().ToList().Where(r => r.UserType != "IND_C").OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }); ViewBag.RoleDetails = new SelectList(RoleDetails, "Value", "Text"); } UserProfile userprofile = new UserProfile(); userprofile.ProfileGUID = new Guid(user.ProfileGUID); userprofile.UserGUID = new Guid(user.UserGUID); userprofile.CompanyName = user.CompanyName; userprofile.FirstName = !string.IsNullOrEmpty(user.FirstName) ? user.FirstName.Trim() : ""; userprofile.LastName = !string.IsNullOrEmpty(user.LastName) ? user.LastName.Trim() : ""; userprofile.MobilePhone = user.MobilePhone; userprofile.BusinessPhone = user.BusinessPhone; userprofile.HomePhone = user.HomePhone; userprofile.EmailID = !string.IsNullOrEmpty(user.EmailID) ? user.EmailID.Trim() : ""; userprofile.AddressLine1 = user.AddressLine1; userprofile.AddressLine2 = user.AddressLine2; userprofile.City = user.City; userprofile.State = user.State; userprofile.Country = user.Country; userprofile.Latitude = latLong.Latitude; userprofile.Longitude = latLong.Longitude; userprofile.ZipCode = user.ZipCode; userprofile.IsDeleted = false; userprofile.PicFileURL = user.ImageURL; userprofile.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) userprofile.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); AspNetUser aspnetuser = new AspNetUser(); aspnetuser.Id = user.UserGUID; aspnetuser.UserName = !string.IsNullOrEmpty(user.UserName) ? user.UserName.Trim() : ""; aspnetuser.FirstName = !string.IsNullOrEmpty(user.FirstName) ? user.FirstName.Trim() : ""; aspnetuser.LastName = !string.IsNullOrEmpty(user.LastName) ? user.LastName.Trim() : ""; aspnetuser.PasswordHash = _IUserRepository.EncodeTo64(user.PasswordHash); aspnetuser.PhoneNumber = user.MobilePhone; aspnetuser.EmailID = !string.IsNullOrEmpty(user.EmailID) ? user.EmailID.Trim() : ""; aspnetuser.OrganizationGUID = new Guid(user.OrganizationGUID); aspnetuser.SecurityStamp = ""; aspnetuser.Discriminator = ""; OrganizationUsersMap organizationUserMap = new OrganizationUsersMap(); organizationUserMap.OrganizationUserMapGUID = new Guid(user.OrganizationUserMapGUID); organizationUserMap.OrganizationGUID = new Guid(user.OrganizationGUID); organizationUserMap.UserGUID = globalUser.UserGUID; organizationUserMap.IsContractor = false; organizationUserMap.IsActive = true; organizationUserMap.Status = 0; if (!string.IsNullOrEmpty(user.RegionGUID) && user.RegionGUID != Guid.Empty.ToString()) { organizationUserMap.RegionGUID = new Guid(user.RegionGUID); } else { organizationUserMap.RegionGUID = null; } if (!string.IsNullOrEmpty(user.TerritoryGUID) && user.TerritoryGUID != Guid.Empty.ToString()) { organizationUserMap.TerritoryGUID = new Guid(user.TerritoryGUID); } else { organizationUserMap.TerritoryGUID = null; } organizationUserMap.UserType = "ENT_A"; organizationUserMap.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.CreateBy = new Guid(Session["UserGUID"].ToString()); organizationUserMap.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); int userresult = _IUserRepository.UpdateUser(aspnetuser); //int userresult = _IUserRepository.Save(); if (userresult > 0) { int guresult = _IGlobalUserRepository.UpdateGlobalUser(globalUser); //int guresult = _IGlobalUserRepository.Save(); if (guresult > 0) { int usrresult = _IUserProfileRepository.UpdateUserProfile(userprofile); //int usrresult = _IUserProfileRepository.Save(); if (usrresult > 0) { if (_IOrganizationRepository.UpdateOrganizationUserMap(organizationUserMap) > 0) { if (oldpassword != user.PasswordHash) { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Password Changed Successfully');</script>"; if (user.UserGUID == Session["UserGUID"].ToString()) return RedirectToAction("../User/Login"); else return RedirectToAction("Index", "MyCompany", new { id = "Users" }); } else if (Session["UserType"] != null && Session["UserType"].ToString() == "SFT_A") { return RedirectToAction("Index", "Organization"); } else if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_A") { return RedirectToAction("Index", "MyCompany", new { id = "Users" }); } else { return RedirectToAction("Dashboard", "User"); } } } } } } else { if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_A") { var RoleDetails = _IGlobalUserRepository.GetRoles().ToList().Where(r => r.UserType != "WIM_A" && r.UserType != "IND_C").OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }); ViewBag.RoleDetails = new SelectList(RoleDetails, "Value", "Text"); } else if (Session["UserType"] != null && Session["UserType"].ToString() == "WIM_A") { var RoleDetails = _IGlobalUserRepository.GetRoles().ToList().Where(r => r.UserType != "IND_C").OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }); ViewBag.RoleDetails = new SelectList(RoleDetails, "Value", "Text"); } var TerritoryDetails = _ITerritoryRepository.GetTerritoryByRegionGUID(new Guid(RegionGUID)).ToList().OrderBy(r => r.Name).Select(r => new SelectListItem { Value = r.TerritoryGUID.ToString(), Text = r.Name }); ViewBag.TerritoryDetails = new SelectList(TerritoryDetails, "Value", "Text"); } return View(user); } else { //TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Session Expired');</script>"; //return RedirectToAction("../User/Login"); return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return View(user); } }
public int UserCreate(AspUser user) { Logger.Debug("Inside CustomerView Controller- UserCreate"); int result = 0; try { if (Session["OrganizationGUID"] != null) { OrganizationSubscription orgSubscription = _IOrganizationSubscriptionRepository.GetOrganizationSubscriptionByOrgID(new Guid(Session["OrganizationGUID"].ToString())); //if (orgSubscription.SubscriptionPurchased > orgSubscription.SubscriptionConsumed) GlobalUser aspuser = _IUserRepository.GlobalUserLogin(user.UserName, Session["OrganizationGUID"].ToString()); if (aspuser == null) { LatLong latLong = new LatLong(); latLong = GetLatLngCode(user.AddressLine1, user.AddressLine2, user.City, user.State, user.Country, user.ZipCode); GlobalUser globalUser = new GlobalUser(); globalUser.UserGUID = Guid.NewGuid(); globalUser.USERID = user.UserID; globalUser.Role_Id = user.RoleGUID; globalUser.UserName = user.UserName; globalUser.Password = _IUserRepository.EncodeTo64(user.PasswordHash); globalUser.IsActive = true; globalUser.IsDelete = false; globalUser.Latitude = latLong.Latitude; globalUser.Longitude = latLong.Longitude; globalUser.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.CreateBy = new Guid(Session["UserGUID"].ToString()); globalUser.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) globalUser.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); OrganizationUsersMap organizationUserMap = new OrganizationUsersMap(); organizationUserMap.OrganizationUserMapGUID = Guid.NewGuid(); organizationUserMap.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); organizationUserMap.UserGUID = globalUser.UserGUID; organizationUserMap.IsContractor = false; organizationUserMap.IsActive = true; organizationUserMap.Status = 0; if (!string.IsNullOrEmpty(user.RegionGUID) && user.RegionGUID != Guid.Empty.ToString()) { organizationUserMap.RegionGUID = new Guid(user.RegionGUID); } else { organizationUserMap.RegionGUID = null; } if (!string.IsNullOrEmpty(user.TerritoryGUID) && user.TerritoryGUID != Guid.Empty.ToString()) { organizationUserMap.TerritoryGUID = new Guid(user.TerritoryGUID); } else { organizationUserMap.TerritoryGUID = null; } organizationUserMap.UserType = "ENT_A"; organizationUserMap.CreateDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.CreateBy = new Guid(Session["UserGUID"].ToString()); organizationUserMap.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) organizationUserMap.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); UserProfile userprofile = new UserProfile(); userprofile.ProfileGUID = Guid.NewGuid(); userprofile.UserGUID = globalUser.UserGUID; userprofile.CompanyName = _IOrganizationRepository.GetOrganizationByID(new Guid(Session["OrganizationGUID"].ToString())).OrganizationFullName; userprofile.FirstName = user.FirstName; userprofile.LastName = user.LastName; userprofile.MobilePhone = user.MobilePhone; userprofile.BusinessPhone = user.BusinessPhone; userprofile.HomePhone = user.HomePhone; userprofile.EmailID = user.EmailID; userprofile.AddressLine1 = user.AddressLine1; userprofile.AddressLine2 = user.AddressLine2; userprofile.City = user.City; userprofile.State = user.State; userprofile.Country = user.Country; userprofile.Latitude = latLong.Latitude; userprofile.Longitude = latLong.Longitude; userprofile.ZipCode = user.ZipCode; userprofile.IsDeleted = false; userprofile.PicFileURL = user.ImageURL; userprofile.LastModifiedDate = DateTime.UtcNow; if (Session["UserGUID"] != null) userprofile.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); AspNetUser aspnetuser = new AspNetUser(); aspnetuser.Id = globalUser.UserGUID.ToString(); aspnetuser.UserName = user.UserName; aspnetuser.FirstName = user.FirstName; aspnetuser.LastName = user.LastName; aspnetuser.PasswordHash = _IUserRepository.EncodeTo64(user.PasswordHash); aspnetuser.PhoneNumber = user.MobilePhone; aspnetuser.EmailID = user.EmailID; aspnetuser.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); aspnetuser.SecurityStamp = ""; aspnetuser.Discriminator = ""; UserSubscription userSubscription = new UserSubscription(); if (orgSubscription != null) { userSubscription.UserSubscriptionGUID = Guid.NewGuid(); userSubscription.UserGUID = globalUser.UserGUID; userSubscription.OrganizationSubscriptionGUID = orgSubscription.OrganizationSubscriptionGUID; userSubscription.IsActive = true; userSubscription.CreatedDate = DateTime.UtcNow; } int userresult = _IUserRepository.InsertUser(aspnetuser); //int userresult = _IUserRepository.Save(); if (userresult > 0) { int guresult = _IGlobalUserRepository.InsertGlobalUser(globalUser); //int guresult = _IGlobalUserRepository.Save(); if (guresult > 0) { int usrresult = _IUserProfileRepository.InsertUserProfile(userprofile); // int usrresult = _IUserProfileRepository.Save(); if (usrresult > 0) { int uSubscriptionResult = _IUserSubscriptionRepository.InsertUserSubscription(userSubscription); //int uSubscriptionResult = _IUserSubscriptionRepository.Save(); if (uSubscriptionResult > 0) { int orgusermap = _IOrganizationRepository.InsertOrganizationUserMap(organizationUserMap); //int orgusermap = _IOrganizationRepository.Save(); if (orgusermap > 0) { orgSubscription.SubscriptionConsumed = orgSubscription.SubscriptionConsumed + 1; result = _IOrganizationSubscriptionRepository.UpdateOrganizationSubscriptionCount(orgSubscription); } else { _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID); //_IUserSubscriptionRepository.Save(); _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); //_IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID); // _IUserProfileRepository.Save(); _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID); //_IGlobalUserRepository.Save(); _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); } } else { _IUserRepository.DeleteUser(aspnetuser.Id); // _IUserRepository.Save(); } } else { _IUserRepository.DeleteUser(aspnetuser.Id); //_IUserRepository.Save(); } } return result; } else { return result; } } catch (Exception ex) { Logger.Error(ex.Message); return 0; } }