Ejemplo n.º 1
0
        public async Task <ActionResult <V1DTO.Address> > PostAddress(V1DTO.Address address)
        {
            var bllEntity = _mapper.Map(address);

            bllEntity.AppUserId = User.UserGuidId();
            _bll.Addresses.Add(bllEntity);
            await _bll.SaveChangesAsync();

            address.Id = bllEntity.Id;
            return(CreatedAtAction(nameof(GetAddress),
                                   new { id = address.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                                   address));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutAddress(Guid id, V1DTO.Address address)
        {
            var userIdTKey = User.IsInRole("Admin") ? null : (Guid?)User.UserGuidId();

            if (id != address.Id)
            {
                return(BadRequest(new V1DTO.MessageDTO("Id and Address.Id do not match")));
            }
            if (!await _bll.Addresses.ExistsAsync(address.Id, userIdTKey))
            {
                return(NotFound(new V1DTO.MessageDTO($"Current user does not have session with this id {id}")));
            }
            var bllEntity = _mapper.Map(address);

            bllEntity.AppUserId = User.UserGuidId();
            await _bll.Addresses.UpdateAsync(bllEntity);

            await _bll.SaveChangesAsync();

            return(NoContent());
        }