public int UpdateTerritory(Territory Territory) { // context.Entry(Territory).State = EntityState.Modified; SqlParameter[] Param = new SqlParameter[7]; Param[0] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[0].Value = Territory.TerritoryGUID; Param[1] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[1].Value = (object)Territory.RegionGUID ?? DBNull.Value; Param[2] = new SqlParameter("@pName", SqlDbType.NVarChar, 50); Param[2].Value = (object)Territory.Name ?? DBNull.Value; Param[3] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)Territory.OrganizationGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pIsDefault", SqlDbType.Bit); Param[4].Value = (object)Territory.IsDefault ?? DBNull.Value; Param[5] = new SqlParameter("@pDescription", SqlDbType.NVarChar, 256); Param[5].Value = (object)Territory.Description ?? DBNull.Value; Param[6] = new SqlParameter("@pTerritoryID", SqlDbType.NVarChar, 256); Param[6].Value = (object)Territory.TerritoryID ?? DBNull.Value; return context.Database.ExecuteSqlCommand("update Territories set RegionGUID=@pRegionGUID,Name=@pName," + "OrganizationGUID=@pOrganizationGUID,IsDefault=@pIsDefault,Description=@pDescription,TerritoryID=@pTerritoryID where TerritoryGUID=@pTerritoryGUID", Param); }
public int InsertTerritory(Territory Territory) { //context.Territories.Add(Territory); SqlParameter[] Param = new SqlParameter[7]; Param[0] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[0].Value = Territory.TerritoryGUID; Param[1] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[1].Value = (object)Territory.RegionGUID ?? DBNull.Value; Param[2] = new SqlParameter("@pName", SqlDbType.NVarChar, 50); Param[2].Value = (object)Territory.Name ?? DBNull.Value; Param[3] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)Territory.OrganizationGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pIsDefault", SqlDbType.Bit); Param[4].Value = (object)Territory.IsDefault ?? DBNull.Value; Param[5] = new SqlParameter("@pDescription", SqlDbType.NVarChar, 256); Param[5].Value = (object)Territory.Description ?? DBNull.Value; Param[6] = new SqlParameter("@pTerritoryID", SqlDbType.NVarChar, 256); Param[6].Value = (object)Territory.TerritoryID ?? DBNull.Value; return context.Database.ExecuteSqlCommand("insert into Territories(TerritoryGUID,RegionGUID,Name,OrganizationGUID,IsDefault,Description,TerritoryID)" + "values(@pTerritoryGUID,@pRegionGUID,@pName,@pOrganizationGUID,@pIsDefault,@pDescription,@pTerritoryID)", Param); }
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); } }
private MobileTerritory convertTerritoryToMobileTerritory(Territory item) { MobileTerritory lterritory = new MobileTerritory(); lterritory.TerritoryGUID = item.TerritoryGUID; lterritory.OrganizationGUID = item.OrganizationGUID; lterritory.Name = item.Name; lterritory.IsDefault = item.IsDefault; lterritory.Description = item.Description; return lterritory; }
public ActionResult Edit(TerritoryModel territory) { Logger.Debug("Inside Region Controller- Edit HttpPost"); try { if (Session["OrganizationGUID"] != null) { if (ModelState.IsValid) { //Territory _territory = _ITerritoryRepository.GetTerritoryByTerritoryID(territory.TerritoryID, new Guid(Session["OrganizationGUID"].ToString())); //if (_territory != null) //{ Territory Territory = new Territory(); Territory.TerritoryGUID = new Guid(territory.TerritoryGUID); if (!string.IsNullOrEmpty(territory.RegionGUID) && territory.RegionGUID != Guid.Empty.ToString()) { Territory.RegionGUID = new Guid(territory.RegionGUID); } else { Territory.RegionGUID = null; } Territory.Name = territory.Name; Territory.Description = territory.Description; if (!string.IsNullOrEmpty(territory.OrganizationGUID) && territory.OrganizationGUID != Guid.Empty.ToString()) { Territory.OrganizationGUID = new Guid(territory.OrganizationGUID); } else { Territory.OrganizationGUID = null; } Territory.TerritoryID = territory.TerritoryID; Territory.IsDefault = false; _ITerritoryRepository.UpdateTerritory(Territory); // _ITerritoryRepository.Save(); return RedirectToAction("Index", "MyCompany", new { id = "Markets", territoryguid = territory.TerritoryGUID }); } //} return View(territory); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return View(territory); } }
public ActionResult Create(TerritoryModel territory, string id = "") { Logger.Debug("Inside Territory Controller- Create HttpPost"); try { if (Session["OrganizationGUID"] != null) { if (ModelState.IsValid) { Territory _territory = _ITerritoryRepository.GetTerritoryByTerritoryID(territory.TerritoryID, new Guid(Session["OrganizationGUID"].ToString())); if (_territory == null) { Territory Territory = new Territory(); Territory.TerritoryGUID = Guid.NewGuid(); if (!string.IsNullOrEmpty(id) && id != Guid.Empty.ToString()) { Territory.RegionGUID = new Guid(id); } else { Territory.RegionGUID = null; } Territory.TerritoryID = territory.TerritoryID; Territory.Name = territory.Name; Territory.Description = territory.Description; Territory.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); Territory.IsDefault = false; _ITerritoryRepository.InsertTerritory(Territory); // _ITerritoryRepository.Save(); return RedirectToAction("Index", "MyCompany", new { id = "Markets", regionguid = Territory.RegionGUID }); } else { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','MarketID already exists');</script>"; if (!string.IsNullOrEmpty(id)) ViewBag.RegionGUID = id; } } else { if (!string.IsNullOrEmpty(id)) ViewBag.RegionGUID = id; } return View(territory); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return View(territory); } }