Beispiel #1
0
        public async Task <IActionResult> ProfileRegions(Guid profileId)
        {
            ViewBag.ProfileId = profileId;
            var regionList         = DataService.GetDto <AtuRegionListDTO>().Select(x => new { regionId = x.Id, name = x.Name });
            var serializerSettings = new JsonSerializerSettings
            {
                StringEscapeHandling = StringEscapeHandling.EscapeHtml
            };

            ViewBag.RegionList = JsonConvert.SerializeObject(regionList, serializerSettings);

            ProfileRowLevelRightDTO entityRls = null;

            {
                try
                {
                    entityRls = await _service.GetOrAddEntityRlsAsync(profileId, nameof(Region));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.InnerException?.Message ?? ex.Message));
                }
            }

            ViewBag.RowLvl         = entityRls.Id;
            ViewBag.RegAccessLevel = entityRls.AccessType;

            return(PartialView("ProfileRegionsPartial"));
        }
        public async Task <ProfileRowLevelRightDTO> GetOrAddEntityRlsAsync(Guid profileId, string entityName)
        {
            var rowLvl    = Guid.Empty;
            var entityRls = (await DataService.GetDtoAsync <ProfileRowLevelRightDTO>(
                                 x => x.ProfileId == profileId && x.EntityName == entityName))
                            .FirstOrDefault();

            if (entityRls == null)
            {
                entityRls = new ProfileRowLevelRightDTO
                {
                    ProfileId  = profileId,
                    EntityName = entityName,
                    AccessType = RowLevelAccessType.Default
                };
                entityRls.Id = DataService.Add <RowLevelRight>(entityRls);
                await DataService.SaveChangesAsync();
            }

            return(entityRls);
        }