Esempio n. 1
0
        public int UpdateManager(RegionUserRoleMapping Regionsmapping)
        {
            string selectquery = @"select count(*) from [dbo].RegionUserRoleMapping  where roletype = @RoleType and regionguid = @regionGuid";
            var    result      = _context.Connection.QuerySingle <int>(selectquery, Regionsmapping);

            if (result > 0)
            {
                string updateQuery = @"update [dbo].RegionUserRoleMapping set userguid = @userGuid where roletype = @RoleType and regionguid = @regionGuid";

                return(_context.Connection.Execute(updateQuery, Regionsmapping));
            }
            else
            {
                string insertQuery = @"INSERT INTO [dbo].RegionUserRoleMapping
                                                                   (
                                                                    RegionUserRoleMappingGuid,
                                                                    RegionGuid, 
                                                                    UserGuid,
                                                                    RoleType, 
                                                                    Keys
                                                                    )
                                  VALUES (
                                                                    @RegionUserRoleMappingGuid,
                                                                    @RegionGuid, 
                                                                    @UserGuid,
                                                                    @RoleType, 
                                                                    @Keys 
                                                                    
                                                                )";
                return(_context.Connection.Execute(insertQuery, Regionsmapping));
            }
        }
Esempio n. 2
0
        private bool InsertRegionKeyPerson(Guid userGuid, Guid regionGuid, string key, string roleType)
        {
            if (userGuid == Guid.Empty || regionGuid == Guid.Empty)
            {
                return(false);
            }
            var manager = new RegionUserRoleMapping();

            manager.RegionUserRoleMappingGuid = Guid.NewGuid();
            manager.UserGuid   = userGuid;
            manager.RegionGuid = regionGuid;
            manager.Keys       = key;
            manager.RoleType   = roleType;
            _regionService.AddUpdateManager(manager);
            return(true);
        }
Esempio n. 3
0
        //[ValidateAntiForgeryToken]
        public IActionResult Edit([FromBody] RegionViewModel regionViewModel)
        {
            try
            {
                var regionModel = Models.ObjectMapper <RegionViewModel, Region> .Map(regionViewModel);

                if (_regionService.CheckDuplicates(regionModel) > 0)
                {
                    ModelState.AddModelError("", "Duplicate value entered for either code or name!!");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                regionModel.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime();
                regionModel.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext);
                var regiondetails = _regionService.GetById(regionModel.RegionGuid);
                regionModel.IsActive  = regiondetails.IsActive;
                regionModel.IsDeleted = regiondetails.IsDeleted;
                regionModel.CreatedBy = regiondetails.CreatedBy;
                regionModel.CreatedOn = regiondetails.CreatedOn;
                _regionService.Edit(regionModel);
                RegionUserRoleMapping regionUserRoleMapping = new RegionUserRoleMapping();
                regionUserRoleMapping.RegionGuid = regionViewModel.RegionGuid;
                regionUserRoleMapping.Keys       = "Region";


                if (regionViewModel.BusinessDevelopmentRegionalManager != null)
                {
                    regionUserRoleMapping.RegionUserRoleMappingGuid = Guid.NewGuid();
                    regionUserRoleMapping.UserGuid = regionViewModel.BusinessDevelopmentRegionalManager;
                    regionUserRoleMapping.RoleType = ContractUserRole._bdregionalManager;
                    //_regionService.AddUpdateManager(regionUserRoleMapping);
                    _contractsService.UpdateAllUserByRole(regionViewModel.BusinessDevelopmentRegionalManager, ContractUserRole._bdregionalManager);
                }

                if (regionViewModel.HSRegionalManager != null)
                {
                    regionUserRoleMapping.RegionUserRoleMappingGuid = Guid.NewGuid();
                    regionUserRoleMapping.UserGuid = regionViewModel.HSRegionalManager;
                    regionUserRoleMapping.RoleType = ContractUserRole._hsregionalManager;
                    //_regionService.AddUpdateManager(regionUserRoleMapping);
                    _contractsService.UpdateAllUserByRole(regionViewModel.HSRegionalManager, ContractUserRole._hsregionalManager);
                }

                if (regionViewModel.DeputyRegionalManager != null)
                {
                    regionUserRoleMapping.RegionUserRoleMappingGuid = Guid.NewGuid();
                    regionUserRoleMapping.UserGuid = regionViewModel.DeputyRegionalManager;
                    regionUserRoleMapping.RoleType = ContractUserRole._deputyregionalManager;
                    //_regionService.AddUpdateManager(regionUserRoleMapping);
                    _contractsService.UpdateAllUserByRole(regionViewModel.DeputyRegionalManager, ContractUserRole._deputyregionalManager);
                }
                if (regionViewModel.RegionalManager != null)
                {
                    regionUserRoleMapping.RegionUserRoleMappingGuid = Guid.NewGuid();
                    regionUserRoleMapping.UserGuid = regionViewModel.RegionalManager;
                    regionUserRoleMapping.RoleType = ContractUserRole._regionalManager;
                    //_regionService.AddUpdateManager(regionUserRoleMapping);
                    _contractsService.UpdateAllUserByRole(regionViewModel.RegionalManager, ContractUserRole._regionalManager);
                }
                //audit log..
                var additionalInformation    = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Edited.ToString(), ResourceType.Region.ToString());
                var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + "/admin/Region";

                var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation);

                var resource = string.Format("{0} </br> GUID: {1} </br> Region Name: {2} </br> Region Code: {3}", ResourceType.Region.ToString(), regionModel.RegionGuid, regionModel.RegionName, regionModel.RegionCode);

                AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), regionModel, resource, regionModel.RegionGuid, UserHelper.GetHostedIp(HttpContext), "Region Edited", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl);

                return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Updated !!" }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 4
0
 public int AddUpdateManager(RegionUserRoleMapping RegionManager)
 {
     return(_regionRepository.AddUpdateManager(RegionManager));
 }
Esempio n. 5
0
        public int UpdateContractUserRole(RegionUserRoleMapping Regionsmapping)
        {
            string updateQuery = "Update contractuserrole set userguid = @UserGuid where userrole = @RoleType";

            return(_context.Connection.Execute(updateQuery, Regionsmapping));
        }