public IActionResult Put(int id, GroupUpdateViewModel model) { var repo = this.Storage.GetRepository <IGroupRepository>(); Group group = repo.WithKey(id); if (group == null) { return(this.NotFound(new { success = false })); } //if (quickLeave == null) //{ // return NotFound("The Employee record couldn't be found."); //} if (this.ModelState.IsValid) { model.ToEntity(group, this.GetCurrentUserName()); repo.Edit(group, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = true })); } return(BadRequest(new { success = false })); }
public async Task <ActionResult <BaseResponse> > Update(GroupUpdateViewModel req) { //本组织管理员或者超级管理员有权限 var GroupId = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value; var isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false; string Code = User.Claims.FirstOrDefault(a => a.Type == "Code").Value; string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; if (!(isAdmin && (GroupId == req.GroupId || Code == _config["Group"]))) { return(Unauthorized("用户没有权限修改此组织信息")); } var rm = await _gs.UpdateAsync(req, Account); return(rm); }
public async Task <BaseResponse> UpdateAsync(GroupUpdateViewModel req, string account) { //检查要修改的组织是否重名 var d = await _group.Find(a => a.GroupName == req.GroupName && a.Id != req.GroupId).ToListAsync(); if (d.Count() > 0) { return(new BaseResponse { Success = false, Message = "已存在相同的组织名称" }); } var g = _group.Find(req.GroupId); if (g == null) { return(new BaseResponse { Success = false, Message = "该组织不存在" }); } try { g.Modify = account; g.ModifyTime = DateTime.Now; g.GroupName = req.GroupName; g.Description = req.Description; await _group.SaveAsync(g); _log.LogInformation($"{account}修改组织{req.GroupId}:{req.GroupName}成功"); return(new BaseResponse { Success = true, Message = "修改数据成功" }); } catch (Exception ex) { _log.LogError($"{account}修改组织信息失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "修改数据失败,请联系管理员" }); } }
public IActionResult Put(int id, GroupUpdateViewModel model) { var repo = this.Storage.GetRepository <IGroupRepository>(); Group group = repo.WithKey(id); if (group == null) { return(this.NotFound(new { success = false })); } if (this.ModelState.IsValid) { model.ToGroupEntity(group); repo.Edit(group, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = "Data berhasil diperbaharui" })); } return(BadRequest(new { success = false })); }