Esempio n. 1
0
        [HttpPost] // PATH URL: api/list
        public async Task <ActionResult <List> > PostListItem(ListModel model)
        {
            // Get the user ID depending on the person that is logged in using JWT
            string userId = User.Claims.First(c => c.Type == "UserID").Value;

            var list = new List()
            {
                Id           = model.Id,
                Description  = model.Description,
                IsCompleted  = 'N',
                LastModified = DateTime.Now,
                UserFK       = userId
            };

            try
            {
                await _context.AddAsync(list);

                await _context.SaveChangesAsync();

                var result = await _context.ApplicationUsers
                             .Include(x => x.Lists)
                             .FirstOrDefaultAsync(x => x.Id == model.UserFK);

                return(Ok(result));  // returns full JSON object with a HTTP 201 result
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateHouse(CreateOrUpdateHouseInput input)
        {
            string userId = User.Claims.First(c => c.Type == "UserID").Value;
            var    user   = await _userManager.FindByIdAsync(userId);

            if (user != null)
            {
                House myHouse = new House {
                    LandlordsId = user.Id, Address = input.Address, Name = input.Name
                };
                await db.AddAsync(myHouse);

                await db.SaveChangesAsync();

                return(Ok(new { Succeeded = "Success" }));
            }

            return(BadRequest());
        }