Example #1
0
        public async Task <IActionResult> Add(RootElement element)
        {
            _db.MachineElements.Add(element);
            await _db.SaveChangesAsync();

            return(Ok(element.MachineElementID));
        }
        public async Task <ActionResult <UserBevarageModel> > Post(UserBevarageModel model)
        {
            try
            {
                var user = Request.HttpContext.User;

                var ub = await _userManager.FindByNameAsync(user.Identity.Name);

                var lastSelection = _context.UserBeverages.AsQueryable()
                                    .FirstOrDefault(p => p.User == ub);


                if (lastSelection == null)
                {
                    _context.UserBeverages.Add(new UserBeverage
                    {
                        Sugar        = model.Sugar,
                        BeverageType = model.BeverageType,
                        UseOwnMug    = model.UseOwnMug,
                        User         = ub
                    });
                }
                else
                {
                    lastSelection.Sugar        = model.Sugar;
                    lastSelection.BeverageType = model.BeverageType;
                    lastSelection.UseOwnMug    = model.UseOwnMug;
                    _context.UserBeverages.Attach(lastSelection);
                }

                // Create a new Camp
                // var camp = _mapper.Map<Camp>(model);
                if (await _context.SaveChangesAsync() > 0)
                {
                    //return Created($"/api/Machine/{camp.Moniker}", _mapper.Map<CampModel>(camp));
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
Example #3
0
        public async Task AddUser(User user)
        {
            _context.Users.Add(user);

            await _context.SaveChangesAsync();
        }