Ejemplo n.º 1
0
        public async Task <IActionResult> PutClientRoom(int id, ClientRoom clientRoom)
        {
            if (id != clientRoom.ClientRoomID)
            {
                return(BadRequest());
            }


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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutCampus(int id, Campus campus)
        {
            if (id != campus.Id)
            {
                return(BadRequest());
            }

            CampusValid valid = new CampusValid(_context, campus);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Campus is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutBlok(int id, Blok blok)
        {
            if (id != blok.Id)
            {
                return(BadRequest());
            }

            BlokValid valid = new BlokValid(_context, blok);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Block is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutRoom(int id, Room room)
        {
            if (id != room.Id)
            {
                return(BadRequest());
            }

            RoomValid valid = new RoomValid(_context, room);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Room is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutDormitory(int id, Dormitory dormitory)
        {
            if (id != dormitory.Id)
            {
                return(BadRequest());
            }

            DormValid valid = new DormValid(_context, dormitory);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Dormitory is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutFloor(int id, Floor floor)
        {
            if (id != floor.Id)
            {
                return(BadRequest());
            }

            FloorValid valid = new FloorValid(_context, floor);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Floor is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PutOrders(int id, Orders orders)
        {
            if (id != orders.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutUniversity(int id, University university)
        {
            if (id != university.Id)
            {
                return(BadRequest());
            }
            UniversityValid valid = new UniversityValid(_context, university);

            if (valid.Valid() == false)
            {
                return(BadRequest("This University is already exist"));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Country")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("Id,Manufacturer,Model,Min_ISO,Max_ISO,Mounting_id")] Camera camera)
        {
            if (ModelState.IsValid)
            {
                _context.Add(camera);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(camera));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,Account_id,Camera_id,Lens_id,Publish_date,Title,Pulse")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Mounting mounting)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mounting);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mounting));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Id,Manufacturer,Model,Aperture,Min_focal_length,Max_focal_length,Mounting_id")] Lens lens)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lens);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lens));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Username,Fullname,Country")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create([Bind("Id,Title,ISBN,Price,Category,AuthorId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Name", book.AuthorId);
            return(View(book));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Update([FromBody] AuthorModel authorCreationModel)
        {
            var db = new Lab2Context();

            var author = db.Authors.FirstOrDefault(x => x.Id == authorCreationModel.Id);

            author.Name = authorCreationModel.Name;

            db.Authors.Update(author);

            await db.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> PutClients(int id, Clients clients)
        {
            if (id != clients.ClientID)
            {
                return(BadRequest());
            }

            var t = _context.Clients.ToList();

            foreach (var tt in t)
            {
                if (tt.Email == clients.Email)
                {
                    return(BadRequest("you're not allowed to create duplicate records"));
                }
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Create([FromBody] AuthorModel authorCreationModel)
        {
            var db = new Lab2Context();

            var newAuthor = new Author
            {
                Id   = authorCreationModel.Id,
                Name = authorCreationModel.Name
            };

            // db.Add(newAuthor);
            await db.Authors.AddAsync(newAuthor);

            await db.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([FromBody] string name)
        {
            var db = new Lab2Context();

            var newAuthor = new Author
            {
                Id   = "5",
                Name = name
            };

            // db.Add(newAuthor);
            await db.Authors.AddAsync(newAuthor);

            await db.SaveChangesAsync();

            return(Ok());
        }