Пример #1
0
        public IHttpActionResult Create([FromBody] UserDTO user)
        {
            string accessType = "";

            ThrowIfUserCannotAccess(accessType);
            if (user == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (user.User_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var userCreateHandler = new UserCreateHandler(Db, ActiveUser, new UserValidator(), new UserFactory(Db, ActiveUser), new UserQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = userCreateHandler.Save(userDTO: user, dateStamp: DateTime.UtcNow);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] UserCreate command)
        {
            try
            {
                var result = await UserCreateHandler.Execute(_db, command);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }