コード例 #1
0
        public async Task <IActionResult> Post([FromBody] Manager entity)
        {
            try
            {
                if (string.IsNullOrEmpty(entity.FirstName) || string.IsNullOrEmpty(entity.LastName) ||
                    string.IsNullOrEmpty(entity.Username) || string.IsNullOrEmpty(entity.Email) ||
                    string.IsNullOrEmpty(entity.Role))
                {
                    return(new BadRequestObjectResult(new Error(errorEnum.e_badRequest, "You are missing one or more required parameter.")));                                   // This returns HTTP 404
                }
                if (string.IsNullOrEmpty(entity.Password))
                {
                    entity.Password = generateDefaultPassword(entity);
                }

                entity.Salt     = Cryptography.CreateSalt();
                entity.Password = Cryptography.GenerateSHA256Hash(entity.Password, entity.Salt);

                if (!isValid(entity))
                {
                    return(new BadRequestResult());                  // This returns HTTP 404
                }
                var x = await shared.Add(entity);

                //remove info not relevant
                x.Salt     = null;
                x.Password = null;

                return(Ok(x));
            }
            catch (Exception ex)
            {
                return(await HandleExceptionAsync(ex));
            }
        }
コード例 #2
0
 public async Task <IActionResult> Post([FromBody] Region entity)
 {
     try
     {
         if (!isValid(entity))
         {
             return(new BadRequestResult());
         }
         return(Ok(await shared.Add(entity)));
     }
     catch (Exception ex)
     {
         return(await HandleExceptionAsync(ex));
     }
 }