public async Task <IActionResult> CreateAsync([FromBody] Account account) { if (account == null) { return(BadRequest("Account information not specified.")); } if (string.IsNullOrEmpty(account.Name)) { return(BadRequest("Account name must be specified.")); } if (string.IsNullOrEmpty(account.DisplayName)) { return(BadRequest("DisplayName must be specified.")); } if (string.IsNullOrEmpty(account.Password)) { return(BadRequest("Password must be specified")); } if (string.IsNullOrEmpty(account.Email)) { return(BadRequest("Email must be specified")); } var accountWithSameName = (await crudProvider .FindBySpecificationAsync <Account>(act => act.Name.Equals(account.Name))).FirstOrDefault(); if (accountWithSameName != null) { return(Conflict($"Account name '{account.Name}' already exists.")); } var accountWithSameEmail = (await crudProvider .FindBySpecificationAsync <Account>(act => act.Email.Equals(account.Email))).FirstOrDefault(); if (accountWithSameEmail != null) { return(Conflict($"Account email '{account.Email}' already exists.")); } account.Password = Utils.EncryptPassword(account.Password, account.Name); await crudProvider.AddAsync(account); return(Created(Url.Action("GetByIdAsync", new { id = account.Id }), account.Id)); }
public async Task <IActionResult> CreateAsync([FromBody] TaskItem task) { if (string.IsNullOrEmpty(task.Name)) { return(BadRequest("未指定任务项目的名称。")); } var existingItem = await crud.FindBySpecificationAsync <TaskItem>(item => item.Name == task.Name); if (existingItem != null && existingItem.Count() > 0) { return(Conflict($"名称为{task.Name}的任务项目已经存在。")); } await crud.AddAsync(task); return(Created(Url.Action("GetByIdAsync", new { id = task.Id }), task.Id)); }