예제 #1
0
        public ActionResult AllRequestIndex()
        {
            var allRequests = new RequestsDTO();

            allRequests.EmployerRequests      = GetEmployerRequestList();
            allRequests.ShiftChangeRequests   = GetShiftChangeRequestList();
            allRequests.ExternalShiftRequests = GetExternalshiftRequestList();

            return(PartialView(allRequests));
        }
예제 #2
0
        public ActionResult DeclineRequest(int reqId, int itemId)
        {
            ItemsDTO    dto  = db.Items.Find(itemId);
            RequestsDTO dto2 = db.Requests.Find(reqId);

            db.Items.Remove(dto);
            db.Requests.Remove(dto2);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public IActionResult GetPendingRequests(string id)
        {
            var requests    = new RequestsDTO();
            var friendships = _context.Friendships
                              .Where(f => (f.SenderId == id || f.ReceiverId == id) && f.Status == FriendshipStatus.Pending)
                              .ToList();

            foreach (var friendship in friendships)
            {
                if (friendship.SenderId == id)
                {
                    requests.Sent.Add(_context.Users.First(u => u.Id == friendship.ReceiverId));
                }
                else
                {
                    requests.Received.Add(_context.Users.First(u => u.Id == friendship.SenderId));
                }
            }

            return(new ObjectResult(requests));
        }
예제 #4
0
        public ActionResult AcceptRequest(int reqId, int itemId)
        {
            ItemsVM item;

            ItemsDTO    dto  = db.Items.Find(itemId);
            RequestsDTO dto2 = db.Requests.Find(reqId);

            if (dto == null)
            {
                return(Content("The item doesn t exist anymore :("));
            }

            //set status to true => the item will be visible
            db.Items.Attach(dto);
            db.Entry(dto).Property(x => x.Status).IsModified = true;
            db.SaveChanges();

            //remove the request
            db.Requests.Remove(dto2);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ICollection <RequestsDTO> GetRequests()
        {
            var requests = _repo.List();

            var allRequests = new List <RequestsDTO>();

            foreach (var request in requests)
            {
                var bar        = _barRepo.GetBarById(request.BarId);
                var user       = _repo.GetUserById(request.UserId);
                var requestDTO = new RequestsDTO
                {
                    Id            = request.Id,
                    UserName      = user.UserName,
                    UserEmail     = user.Email,
                    PhoneNumber   = bar.PhoneNumber,
                    BarName       = bar.Name,
                    DateRequested = request.DateRequested
                };

                allRequests.Add(requestDTO);
            }
            return(allRequests);
        }
예제 #6
0
        public ActionResult AddItem(ItemsVM item, HttpPostedFileBase file)
        {
            //rebuild the selectList
            item.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");

            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            ItemsDTO dto = new ItemsDTO();

            dto.Title       = item.Title;
            dto.Description = item.Description;
            dto.Price       = item.Price;
            dto.Score       = -1;
            dto.CategoryId  = item.CategoryId;

            CategoriesDTO catDto = db.Categories.FirstOrDefault(x => x.Id == item.CategoryId);

            dto.CategoryName = catDto.Name;

            //insert and commit
            db.Items.Add(dto);
            db.SaveChanges();

            TempData["Status"] = "The item was added! <3";

            //also insert the item in the request table for approval
            RequestsDTO dto2 = new RequestsDTO();

            dto2.UserId = 0;
            dto2.ItemId = dto.Id;

            db.Requests.Add(dto2);
            db.SaveChanges();

            int id = dto.Id;

            var directory = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\")));
            var path1     = Path.Combine(directory.ToString(), "Items");
            var path2     = Path.Combine(directory.ToString(), "Items" + id.ToString());

            if (file != null && file.ContentLength > 0)
            {
                string extension = file.ContentType.ToLower();

                if (extension != "image/jpg" && extension != "image/jpeg" && extension != "image/png")
                {
                    item.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
                    ModelState.AddModelError("", "The image was not uploaded - wrong image extension.");
                    return(View(item));
                }


                string imageName = file.FileName;

                ItemsDTO dto1 = db.Items.Find(id);
                dto1.Image = imageName;

                db.SaveChanges();

                file.SaveAs(string.Format("{0}.png", path2));

                WebImage img = new WebImage(file.InputStream);
                img.Resize(200, 200);
                img.Save(path2, "png", true);
            }

            return(RedirectToAction("AddItem"));
        }
예제 #7
0
 public RequestsVM(RequestsDTO req)
 {
     Id     = req.Id;
     UserId = req.UserId;
     ItemId = req.ItemId;
 }
예제 #8
0
 public void DeleteRequest(RequestsDTO dto)
 {
     _service.DeleteRequest(dto.Id);
 }