Пример #1
0
        public async Task <IActionResult> Create([Bind("BookingId,UserId,LectureId")] Booking booking)
        {
            bool waitListFound = false;

            if (ModelState.IsValid)
            {
                Lecture l = _context.Lecture.FindAsync(booking.LectureId).Result;
                if (l.Spaces < 1)
                {
                    booking.WaitList = 1;
                    //WaitListsController wlCon = new WaitListsController(_context);
                    //WaitList wl = new WaitList(booking);
                    //wlCon.Create(wl);
                    //return RedirectToAction(nameof(Index));
                    waitListFound = true;
                }

                _context.Add(booking);
                await _context.SaveChangesAsync();

                if (waitListFound == false)
                {
                    LecturesController con = new LecturesController(_context);
                    con.Edit(booking.LectureId, _context.Lecture.FindAsync(booking.LectureId).Result);
                }

                //CreateUpdateLecture(booking);

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["LectureId"] = new SelectList(_context.Lecture, "LectureId", "Title", booking.LectureId);
            ViewData["UserId"]    = new SelectList(_context.User, "UserId", "Email", booking.UserId);
            return(View(booking));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("RoomId,Name,Capacity")] Room room)
        {
            if (ModelState.IsValid)
            {
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
        public async Task <IActionResult> Create([Bind("UserId,FirstName,LastName,Email,Address,Telephone,Zipcode,AddAutismInfo")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Пример #4
0
        public async Task <ActionResult> Create([Bind(Include = "PersonId,FirstName,LastName,Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
        public async Task <IActionResult> Create([Bind("LectureId,RoomId,Title,StartTime,Speaker,CategoryId,Description,TimeFrame")] Lecture lecture)
        {
            //lecture.Spaces = SpacesCount(lecture);

            if (ModelState.IsValid)
            {
                lecture.Spaces = _context.Room.FindAsync(lecture.RoomId).Result.Capacity;
                _context.Add(lecture);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomId"]     = new SelectList(_context.Room, "RoomId", "Name", lecture.RoomId);
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "Name", lecture.CategoryId);
            return(View(lecture));
        }
Пример #6
0
        public async Task <ActionResult <IEnumerable <dynamic> > > CreateMessageByUser(string username, [FromBody] CreateMessage model)
        {
            UpdateLatest();
            // if(GetUserId(username) == -1) {
            //  _logger.LogWarning("Error: {user}, does not exist in the database", username);
            // return BadRequest("Error!");
            // }
            Message message = new Message();

            message.author_id = _context.user.Single(x => x.username == username).user_id;
            message.text      = model.content;
            message.pub_date  = (Int32)(DateTimeOffset.Now.ToUnixTimeSeconds());
            message.flagged   = 0;

            _context.message.Add(message);
            await _context.SaveChangesAsync();

            // _logger.LogInformation("API user {userID}, posted a new message", message.author_id.ToString());
            return(NoContent());
        }
Пример #7
0
        public async Task <ActionResult <IEnumerable <dynamic> > > CreateMessageByUser(string username, [FromBody] CreateMessage model)
        {
            UpdateLatest();
            if (GetUserId(username) == -1)
            {
                return(BadRequest("error"));
            }
            Message message = new Message();

            message.author_id = _context.user.Single(x => x.username == username).user_id;
            message.text      = model.content;
            message.pub_date  = (Int32)(DateTimeOffset.Now.ToUnixTimeSeconds());
            message.flagged   = 0;

            _context.message.Add(message);
            await _context.SaveChangesAsync();

            // return Ok("Message posted");
            return(NoContent());
        }
        public async Task <bool> Create([Bind("WaitListId,UserId,LectureId")] WaitList waitlist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(waitlist);
                await _context.SaveChangesAsync();

                return(true);
                //return RedirectToAction(nameof(Index));
            }

            return(false);
            //ViewData["LectureId"] = new SelectList(_context.Lecture, "LectureId", "Title", booking.LectureId);
            //ViewData["UserId"] = new SelectList(_context.User, "UserId", "Email", booking.UserId);
            //return View(booking);
        }
Пример #9
0
 public async Task <int> SaveChanges()
 {
     return(await _dbContext.SaveChangesAsync());
 }
Пример #10
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }