public virtual async Task <ActionResult <TUpdate> > Update(string id, [FromBody] TUpdate data) { if (data != null) { ReflectionHelper.SetPropertyValue(data, new JProperty("ModifiedBy", _mixIdentityHelper.GetClaim(User, MixClaims.Username))); ReflectionHelper.SetPropertyValue(data, new JProperty("LastModified", DateTime.UtcNow)); var currentId = ReflectionHelper.GetPropertyValue(data, MixQueryColumnName.Id).ToString(); if (id != currentId) { return(BadRequest()); } var result = await SaveAsync(data, true); return(GetResponse(result)); } else { return(BadRequest(new NullReferenceException())); } }
public async Task <RepositoryResponse <UpdateViewModel> > Save([FromBody] UpdateViewModel model) { if (model != null) { model.CreatedBy = _idHelper.GetClaim(User, MixClaims.Username); var result = await base.SaveAsync <UpdateViewModel>(model, true); return(result); } return(new RepositoryResponse <UpdateViewModel>() { Status = 501 }); }
public virtual async Task <IActionResult> Update(string id, [FromBody] TUpdate data) { if (data != null) { ReflectionHelper.SetPropertyValue(data, new JProperty("ModifiedBy", _mixIdentityHelper.GetClaim(User, MixClaims.Username))); ReflectionHelper.SetPropertyValue(data, new JProperty("LastModified", DateTime.UtcNow)); var currentId = ReflectionHelper.GetPropertyValue(data, MixQueryColumnName.Id).ToString(); if (id != currentId) { return(BadRequest()); } var result = await SaveAsync(data, true); if (result.IsSucceed) { return(Ok(result.Data)); } else { var current = await GetSingleAsync(currentId); if (!current.IsSucceed) { return(NotFound()); } else { return(BadRequest(result.Errors)); } } } else { return(BadRequest(new NullReferenceException())); } }
public void OnAuthorization(AuthorizationFilterContext context) { bool isAuthorized = _idService.CheckEndpointPermission( context.HttpContext.User, context.HttpContext.Request.Path, context.HttpContext.Request.Method); if (!isAuthorized) { context.Result = new UnauthorizedResult(); } context.HttpContext.Request.EnableBuffering(); context.HttpContext.Request.Headers.Add("RequestId", Guid.NewGuid().ToString()); _auditlogRepo.Log( _mixIdentityHelper.GetClaim(context.HttpContext.User, MixClaims.Username), context.HttpContext.Request, false, null); context.HttpContext.Request.Body.Seek(0, System.IO.SeekOrigin.Begin); }
public async Task <RepositoryResponse <UpdateViewModel> > Save([FromBody] UpdateViewModel model) { if (model != null) { model.CreatedBy = _idHelper.GetClaim(User, MixClaims.Username); // Only savesubmodels when create new => clone data from default culture var result = await base.SaveAsync <UpdateViewModel>(model, model.Id == 0); if (result.IsSucceed) { MixService.SetConfig("LastUpdateConfiguration", DateTime.UtcNow); } return(result); } return(new RepositoryResponse <UpdateViewModel>() { Status = 501 }); }
public async Task <RepositoryResponse <Lib.ViewModels.MixPortalPageRoles.ReadViewModel> > Update( [FromBody] Lib.ViewModels.MixPortalPageRoles.ReadViewModel model) { var result = new RepositoryResponse <Lib.ViewModels.MixPortalPageRoles.ReadViewModel>() { IsSucceed = true, Data = model }; if (model != null) { if (model.IsActived) { model.CreatedBy = _mixIdentityHelper.GetClaim(User, MixClaims.Username); var saveResult = await model.SaveModelAsync(false); result.IsSucceed = saveResult.IsSucceed; if (!result.IsSucceed) { result.Exception = saveResult.Exception; result.Errors.AddRange(saveResult.Errors); } } else { var saveResult = await model.RemoveModelAsync(false); if (!result.IsSucceed) { result.Exception = saveResult.Exception; result.Errors.AddRange(saveResult.Errors); } } return(result); } return(new RepositoryResponse <Lib.ViewModels.MixPortalPageRoles.ReadViewModel>()); }