コード例 #1
0
 public IActionResult AddRoom([FromBody] RoomModel room)
 {
     try
     {
         if (room == null)
         {
             return(BadRequest("Empty body request"));
         }
         else
         {
             RoomDto room1 = new RoomDto
             {
                 //Id = room.Id,
                 Description      = room.Description,
                 ReservationPrize = room.ReservationPrize
             };
             _db.Rooms.Add(room1);
             _db.SaveChanges();
             return(Created("Room Added", room1));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Bład przy dodawaniu pokoju do bazy /n" + ex.Message));
     }
 }
コード例 #2
0
        public IActionResult Delete(int id)
        {
            var del = _res.Reservations.Find(id);

            _res.Reservations.Remove(del);
            _res.SaveChanges();
            _toastNotification.AddWarningToastMessage("You deleted your reservation");
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "Id,TrainId,Stop,ArrivalTime")] TrainSchedule trainSchedule)
        {
            if (ModelState.IsValid)
            {
                db.TrainSchedules.Add(trainSchedule);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trainSchedule));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstName,Phone,StrAdd,City,State")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,BookISBN,StudentId,Doyoureserve,Date")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservation.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(reservation));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "Id,Name,SName,Grade")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Student.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "id,check_in_date,check_out_date,room_count,reserve_date,cancel_date,notes,user_id")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(reservation));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "Id,TrainId,TrainName,Source,Destination,DateOfTravel,TimeOfArrival,TrainType,SeatAvailability,NoOfSeat")] Train train)
        {
            if (ModelState.IsValid)
            {
                db.Trains.Add(train);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(train));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "ID,UserName,Hair,Gender")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstName,Occupation")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
コード例 #11
0
        public ActionResult Create([Bind(Include = "ISBN,Title,Detail")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Book.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
コード例 #12
0
        public ActionResult Create([Bind(Include = "ReservationID,UserID,Hair,ReservationDate")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", reservation.UserID);
            return(View(reservation));
        }
コード例 #13
0
        public ActionResult Create([Bind(Include = "ID,ReservationDate,CourseID,StudentID")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseID  = new SelectList(db.Courses, "CourseID", "Name", reservation.CourseID);
            ViewBag.StudentID = new SelectList(db.Students, "StudentID", "FirstName", reservation.StudentID);
            return(View(reservation));
        }
コード例 #14
0
        public ActionResult Create([Bind(Include = "ReservationID,ClientID,EmployeeID,Date,Time,ClientName,EmployeeName")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClientID   = new SelectList(db.Clients, "ID", "LastName", reservation.ClientID);
            ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "LastName", reservation.EmployeeID);
            return(View(reservation));
        }
コード例 #15
0
        public void Save(Contact contact)
        {
            try
            {
                _context.contacts.Update(contact);

                _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #16
0
        public ActionResult Register(User user)
        {
            if (ModelState.IsValid)
            {
                con.Users.Add(user);
                con.SaveChanges();
                //return View();

                //Response.Write("<script>alert('Registered successfully')</script>");
                return(RedirectToAction("Login", "User", new { msg = "success" }));
            }

            return(View(user));
        }
コード例 #17
0
        public ActionResult Newpassword(FormCollection form)
        {
            try
            {
                string newpass = form["Newpass"].ToString();
                string conpass = form["Conpass"].ToString();
                string adid    = (string)Session["passrecovery"];
                if (newpass == conpass)
                {
                    var admin = con.Admins.Where(t => t.UserId == adid).FirstOrDefault();
                    admin.password = newpass;
                    con.SaveChanges();
                    return(RedirectToAction("Passwordsuccess", "Admin"));
                }
                else
                {
                    //ModelState.AddModelError("", "Newpassword and confirm password does not match");
                    Response.Write("<center><h2 style=" + "color:red" + ">Newpassword and confirm password does not match</h2></center>");
                    // return View();
                }

                return(View());
            }
            catch
            {
                Response.Write("<center><h2 style=" + "color:red" + ">Password cannot be empty</h2></center>");
                return(View());
            }
        }
コード例 #18
0
ファイル: InsertControler.cs プロジェクト: alishov/ProjectIT
 public bool InsertIntoCoutries(string coutryName)
 {
     if (find.FindCountry(coutryName) == null)
     {
         context.Countries.Add(
             new Country()
         {
             Name = coutryName
         });
         context.SaveChanges();
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #19
0
 public virtual void Edit(T entity)
 {
     using (context = new ReservationContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
         //context.Entry(entity).Reload();
     }
 }
コード例 #20
0
        public ReservationController(ReservationContext context)
        {
            _context = context;

            if (_context.ReservationItems.Count() == 0)
            {
                _context.SaveChanges();
            }
        }
コード例 #21
0
        public ActionResult <IEnumerable <string> > Get()
        {
            var room = new Room {
                Name = "room1"
            };

            _db.Rooms.Add(room);
            _db.SaveChanges();

            return(new string[] { "value1", "value2" });
        }
コード例 #22
0
ファイル: ComponentTests.cs プロジェクト: AlexStangier/VvSdH2
        public void TearDown()
        {
            using var context = new ReservationContext();
            var dummyData = context.Reservations.Where(x => x.StartTime > new DateTime(2021, 12, 31));

            foreach (var reservation in dummyData)
            {
                context.Reservations.Remove(reservation);
            }

            context.SaveChanges();
        }
コード例 #23
0
 public int Add(T entity)
 {
     using (context = new ReservationContext())
     {
         context.Set <T>().Add(entity);
         context.SaveChanges();
         DbPropertyValues sa      = context.Entry(entity).GetDatabaseValues();
         string           keyName = sa.PropertyNames.First();
         int Id = sa.GetValue <int>(keyName);
         return(Id);
     }
 }
コード例 #24
0
        public void DeleteReservation(Guid reservationId)
        {
            ReservationContext context = new ReservationContext();

            Reservation reservation = (from r in context.Reservations where r.Id == reservationId select r).FirstOrDefault();

            if (reservation == null)
            {
                throw new ArgumentException(string.Format("There's no reservation by ID {0}", reservationId));
            }
            context.Entry <Reservation>(reservation).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
コード例 #25
0
        public void AddReservation(AddReservationValidationResult addReservationValidationResult)
        {
            ReservationContext context = new ReservationContext();

            if (addReservationValidationResult.ValidationComplete)
            {
                context.Entry <Reservation>(addReservationValidationResult.ToBeInserted).State = System.Data.Entity.EntityState.Added;
            }
            else
            {
                throw new InvalidOperationException("Validation is not complete. You have to call the AddReservation method of the Timetable class first.");
            }

            context.SaveChanges();
        }
コード例 #26
0
        public XmlExtractorController(ExpenseContext expenseContext, ReservationContext reservationContext)
        {
            ReservationContext = reservationContext;

            if (reservationContext.ReservationItems.Count() == 0)
            {
                reservationContext.SaveChanges();
            }

            ExpenseContext = expenseContext;

            if (expenseContext.ExpenseItems.Count() == 0)
            {
                expenseContext.SaveChanges();
            }
        }
コード例 #27
0
ファイル: SeatSelector.cs プロジェクト: jdpoints/SeatSaver
        private Order CreateOrder(int customerID, int eventID, List <Seat> seats)
        {
            if (seats.Count > 0)
            {
                Order newOrder = new Order();

                using (var db = new ReservationContext())
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            newOrder.CustomerID = customerID;
                            newOrder.EventID    = eventID;

                            db.Orders.Add(newOrder);

                            foreach (Seat seat in seats)
                            {
                                OrderSeat newSeat = new OrderSeat();
                                newSeat.OrderID = newOrder.ID;
                                newSeat.SeatID  = seat.ID;

                                newOrder.OrderSeats.Add(newSeat);
                                db.OrderSeats.Add(newSeat);
                            }

                            db.SaveChanges();
                            transaction.Commit();

                            newOrder = db.Orders
                                       .Include(i => i.OrderSeats.Select(s => s.Seat.Row))
                                       .Where(w => w.ID.Equals(newOrder.ID))
                                       .FirstOrDefault();

                            return(newOrder);
                        }
                        catch
                        {
                            transaction.Rollback();
                        }
                    }
            }

            return(null);
        }
コード例 #28
0
ファイル: UserController.cs プロジェクト: AlexStangier/VvSdH2
        public async Task <bool> Logout(string username)
        {
            using var context = new ReservationContext();

            var currentUser = await context.Users.FirstOrDefaultAsync(x => x.Username.Equals(username));

            if (currentUser == null)
            {
                return(false);
            }

            currentUser.HasCurrentSession = false;

            context.SaveChanges();

            //Default for HasCurrentSession should be false
            return(!currentUser.HasCurrentSession);
        }
コード例 #29
0
        //[HttpGet]
        public IActionResult EditIncoming(int exchangeid, bool accept)
        {
            ExchangeReservation exchangeReservation = _databaseHandler.GetExchangeReservationById(exchangeid);

            if (_userManager.GetUserAsync(User).Result.Id == exchangeReservation.TeacherFrom)
            {
                exchangeReservation.ExchangeAccepted = accept;
                if (accept)
                {
                    _databaseHandler.ExchangeReservation(exchangeReservation.TeacherFrom,
                                                         exchangeReservation.ReservationFromId, exchangeReservation.TeacherTo,
                                                         exchangeReservation.ReservationOfferId);
                }
            }

            exchangeReservation.ExchangeStatus = true;
            _reservationContext.Entry(exchangeReservation).State = EntityState.Modified;
            _reservationContext.SaveChanges();
            return(RedirectToAction("Anfragen"));
        }
コード例 #30
0
        public async Task <bool> UpdateReservation(Reservation currReservation, DateTime newTime,
                                                   int newSlot)
        {
            await using var context = new ReservationContext();

            var reservation = await context.Reservations
                              .Where(x => x.ReservationId == currReservation.ReservationId)
                              .Include(y => y.User)
                              .ThenInclude(z => z.Rights)
                              .FirstOrDefaultAsync();

            if (reservation == null)
            {
                return(false);
            }
            var timestamp = getTimestampsFromTimeslot(newSlot, newTime);

            reservation.StartTime = timestamp.start;
            reservation.EndTime   = timestamp.end;
            return(context.SaveChanges() > 0);
        }