Esempio n. 1
0
        public async Task <IActionResult> PutMessage(long id, Message message)
        {
            if (id != message.Id)
            {
                return(BadRequest());
            }

            _context.Entry(message).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAddress(long id, [FromForm] Address address)
        {
            if (id != address.Id)
            {
                return(BadRequest());
            }

            _context.Entry(address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PostLendTableEntry(ToyViewModel toyModel)
        {
            var toy = new Toy
            {
                Name  = toyModel.Name,
                Price = Currency.Parse(toyModel.Price)
            };

            _context.Toy.Add(toy);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult <HttpStatusCode> > PostServer([FromBody] Server serv)
        {
            IdGenerator generator = new IdGenerator(db);
            IdNumber    temp      = new IdNumber(serv.Id);

            // Check if provided ID or URL already exist in DB.
            var val = db.Servers.Where(s => s.Url == serv.Url).FirstOrDefault();

            if (generator.IsUnique(temp) && val == null)
            {
                // If not, add new server.
                db.Servers.Add(serv);
                db.IdNumbers.Add(temp);
                await db.SaveChangesAsync();

                return(HttpStatusCode.Created);
            }
            // Otherwise return conflict status code.
            return(StatusCode(409));
        }
Esempio n. 5
0
        public async Task <ActionResult <User> > Create(User user)
        {
            if (user == null)
            {
                return(BadRequest());
            }
            user.UserId = "";
            db.Users.Add(user);
            await db.SaveChangesAsync();

            return(Ok(user));
        }