public IActionResult Patch(string id, [FromBody] JsonPatchDocument <TenSetting> tenantSettingPatch)
        {
            try
            {
                if (Guid.TryParse(id, out Guid parsedId))
                {
                    //var userId = User.FindFirstValue("sub");

                    TenantSetting tenantSetting = _unitOfWork.TenantSettings.Get(parsedId);

                    TenSetting tenSetting = _mapper.Map <TenSetting>(tenantSetting);

                    tenantSettingPatch.ApplyTo(tenSetting);

                    _mapper.Map(tenSetting, tenantSetting);

                    _unitOfWork.Complete();

                    return(CreatedAtRoute("Get", new { id = _mapper.Map <TenSetting>(tenantSetting).Id }, _mapper.Map <TenSetting>(tenantSetting)));
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }
Пример #2
0
        public async Task <IActionResult> OnGetAsync()
        {
            var accessToken = await HttpContext.GetTokenAsync("access_token");

            await PageConstructor(SaveStates.IGNORE, accessToken);

            if (!await _apiHelper.AuthCheck(accessToken, User.FindFirst("sub").Value))
            {
                return(RedirectToPage("/Logout"));
            }

            var response = await _apiHelper.MakeAPICallAsync(accessToken, HttpMethod.Get, APITypes.FOUNDATION, $"Setting/{Id}");

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                tenSetting = response.ContentAsType <TenSetting>();
            }
            else
            {
                tenSetting = new TenSetting();
            }

            SaveMessageModel = await _apiHelper.GenerateSaveMessageModel(accessToken);

            return(Page());
        }
        public IActionResult Post([FromBody] TenSetting tenSetting)
        {
            try
            {
                if (tenSetting.Id == Guid.Empty)
                {
                    var foundExisting = _unitOfWork.TenantSettings.GetTenantSetting(tenSetting.Id);

                    if (foundExisting == null)
                    {
                        //var userId = User.FindFirstValue("sub");

                        var tenantSetting = _mapper.Map <TenantSetting>(tenSetting);
                        tenantSetting.Status = StatusTypes.Open;

                        _unitOfWork.TenantSettings.Add(tenantSetting);

                        _unitOfWork.Complete();

                        return(Created(new Uri($"{Request.Path}/{tenantSetting.Id}", UriKind.Relative), _mapper.Map <TenSetting>(tenantSetting)));
                    }
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }