Exemplo n.º 1
0
        public async Task<IHttpActionResult> PutUser(UserDto modifiedUser)
        {
            if (modifiedUser.Address == null)
            {
                modifiedUser.Address = new AddressDto();
            }

            await this.usersRepository.UpdateUser(new User()
            {
                Id = modifiedUser.Id,

                Profile = new UserProfile()
                {
                    LastModified = DateTime.UtcNow,
                    FirstName = modifiedUser.FirstName,
                    LastName = modifiedUser.LastName,
                    CurrentTradeRole = Mapper.MapTradeRoleDtoToEntity(modifiedUser.CurrentTradeRole),
                    Address = Mapper.MapAddressDtoToEntity(modifiedUser.Address)
                }
            });

            return StatusCode(HttpStatusCode.NoContent);;
        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> PostUser(UserDto newUser)
        {
            Guid userId = Guid.NewGuid();
            DateTime dateCreated = DateTime.UtcNow;

            var user = new User()
            {
                Id = userId,
                Created = dateCreated,
                Username = newUser.Username,
                Password = HashHelper.GetHash(newUser.Password, HashType.MD5),
                Profile = new UserProfile()
                {
                    Id = Guid.NewGuid(),
                    Created = dateCreated,
                    LastModified = dateCreated,
                    FirstName = newUser.FirstName,
                    LastName = newUser.LastName,
                    CurrentTradeRole = Mapper.MapTradeRoleDtoToEntity(newUser.CurrentTradeRole)
                }
            };

            await this.usersRepository.CreateUser(user);
            newUser.Id = userId;

            return CreatedAtRoute("DefaultApi", new { id = user.Id }, newUser);
        }