public Customer AddCustomer([FromBody] Customer cust)
        {
            Customer newCust = new Customer {
                Name = cust.Name
            };

            db.Add(newCust);
            db.SaveChanges();
            return(newCust);
        }
示例#2
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));
        }
        public IActionResult Follow(List <Int32> values)
        {
            Follower follower = new Follower();

            follower.who_id  = values[1];
            follower.whom_id = values[0];
            _context.Add(follower);
            _context.SaveChanges();

            return(RedirectToAction("Timeline"));
        }
示例#4
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));
        }
示例#6
0
        public IActionResult Follow(List <Int32> values)
        {
            Follower follower = new Follower();

            follower.who_id  = values[1];
            follower.whom_id = values[0];
            _context.Add(follower);
            _context.SaveChanges();
            _logger.LogInformation("{whoID}, now follows {whomID}.", follower.who_id.ToString(), follower.whom_id.ToString());
            return(RedirectToAction("Timeline"));
        }
        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);
        }
        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));
        }
示例#9
0
        public IActionResult Follow(string username, int no_followers = 100)
        {
            var verb   = _accessor.HttpContext.Request.Method.ToString();
            var json   = _accessor.HttpContext.Request.ReadFromJsonAsync <ApiDataFollow>();
            int userid = GetUserId(username);

            UpdateLatest();
            if (userid == -1)
            {
                _logger.LogWarning("No user exist for {Username}.", username);
                return(BadRequest("error"));
            }

            if (verb == "POST" && json.Result.follow != null)
            {
                string userToFollow   = json.Result.follow;
                int    userToFollowId = GetUserId(userToFollow); //find the id of user to follow
                if (userToFollowId == -1)
                {
                    return(NotFound());
                }

                var followersOfUserId = _context.follower.Where(f => f.who_id == userid).ToList();

                if (followersOfUserId.Where(f => f.whom_id == userToFollowId).Any())
                {
                    //_logger.LogInformation("{whoID}, already follows {whomID}.", userid.ToString(), userToFollowId.ToString());
                    return(BadRequest(username + " already follows " + userToFollow));
                }

                Follower follower = new Follower();
                follower.who_id  = userid;
                follower.whom_id = userToFollowId;
                _context.Add(follower);
                _context.SaveChanges();
                //_logger.LogInformation("{whoID}, now follows {whomID}.", userid.ToString(), userToFollowId.ToString());
                return(NoContent());
            }
            else if (verb == "POST" && json.Result.unfollow != null)
            {
                string userToUnfollow   = json.Result.unfollow;
                int    userToUnfollowId = GetUserId(userToUnfollow);
                if (userToUnfollowId == -1)
                {
                    return(NotFound());
                }

                var followersOfUserId = _context.follower.AsNoTracking().Where(f => f.who_id == userid).ToList();

                if (!followersOfUserId.Where(f => f.whom_id == userToUnfollowId).Any())
                {
                    //_logger.LogInformation("{whoID}, is not currently following {whomID}.", userid.ToString(), userToUnfollowId.ToString());
                    return(BadRequest(username + " isn't following " + userToUnfollow + " to begin with"));
                }

                Follower follower = new Follower();
                follower.who_id  = userid;
                follower.whom_id = userToUnfollowId;
                _context.Remove(follower);
                _context.SaveChanges();
                //_logger.LogInformation("{whoID}, is not following {whomID} anymore.", userid.ToString(), userToUnfollowId.ToString());
                return(NoContent());
            }
            else if (verb == "GET")   //needs refactoring to use ORM instead of query
            {
                var query = (from f in _context.follower

                             join u in _context.user on f.whom_id equals u.user_id
                             where f.who_id == userid
                             select
                             new { u.username })
                            .Take(no_followers).ToList();
                List <string> Follows = new List <string>();
                foreach (var item in query)
                {
                    Follows.Add(item.username);
                }
                ApiDataFollows returnfollows = new ApiDataFollows {
                    follows = Follows
                };
                var jsonreturn = JsonSerializer.Serialize(returnfollows);
                //_logger.LogInformation("Fetched follower list for {whoID}", userid.ToString());
                return(Ok(jsonreturn));
            }
            return(Ok("other"));
        }