public async Task <JsonResult> SaveGroup([FromBody] SaveGroupInput input) { var result = await _user.SaveGroup(input); return(Json(new { Data = new { IsSuccess = result.IsSuccess } }, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); }
public async Task <SimpleResult> SaveGroup(SaveGroupInput input) { try { if (input.Id != null) { var existingGroup = await _context.UserGroups.FindAsync(input.Id); await _userDomain.UpdateGroup(existingGroup); return(new SimpleResult { IsSuccess = true }); } else { var modules = new List <ModulePoco>(); foreach (var x in input.Modules) { var mod = await _context.Modules.FindAsync(x.Value); modules.Add(mod); } var group = new UserGroupPoco { AccessLevel = (AccessLevel)input.Access.Value, Title = input.Title, Description = input.Description, Modules = JsonConvert.SerializeObject(modules, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }) }; await _userDomain.AddGroup(group); return(new SimpleResult { IsSuccess = true }); } } catch (Exception ex) { return(new SimpleResult { IsSuccess = false, ErrorMessage = JsonConvert.SerializeObject(ex) }); } }