public HttpResponseMessage GetFriendById(int friendId)
        {
            Friend getFriend = new Friend();

            if (friendRepository == null)
            {
                FriendRepository friendRepository = new FriendRepository();
                getFriend = friendRepository.GetFriendById(friendId);
            }
            else
            {
                getFriend = friendRepository.GetFriendById(friendId);
            }

            if (getFriend != null)
            {
                FriendViewModel friend = new FriendViewModel();

                friend.Id   = getFriend.Id;
                friend.Name = getFriend.Name.Trim();
                friend.Sex  = getFriend.Sex;
                friend.Age  = getFriend.Age.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, friend));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "null"));
        }
Beispiel #2
0
        public HttpResponseMessage GetPaymentById(int paymentId)
        {
            Payment getPayment = new Payment();

            if (paymentRepository == null)
            {
                PaymentRepository paymentRepository = new PaymentRepository();
                getPayment = paymentRepository.GetPaymentById(paymentId);

                if (getPayment != null)
                {
                    PaymentViewModel payment = new PaymentViewModel();
                    payment.Id    = getPayment.Id;
                    payment.Date  = Convert.ToString(getPayment.Date);
                    payment.Value = Convert.ToString(getPayment.Value);
                    FriendRepository friendName = new FriendRepository();
                    payment.FriendNameIn  = friendName.GetFriendNameById(getPayment.FriendIdIn).Trim();
                    payment.FriendNameOut = friendName.GetFriendNameById(getPayment.FriendIdOut).Trim();

                    return(Request.CreateResponse(HttpStatusCode.OK, payment));
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find payment."));
            }
            else
            {
                getPayment = paymentRepository.GetPaymentById(paymentId);

                if (getPayment != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, getPayment));
                }
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find payment."));
        }
        public HttpResponseMessage DeleteFriendById([FromUri] int friendId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateDelete(friendId);

            if (Message == String.Empty)
            {
                Friend friend = new Friend();

                if (friendRepository == null)
                {
                    FriendRepository friendRepository = new FriendRepository();
                    friend = friendRepository.GetFriendById(friendId);

                    if (friend != null)
                    {
                        Boolean sucess = friendRepository.DeleteObject(friend, true);

                        if (sucess)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.NoContent));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not delete record."));
                    }
                }
                else
                {
                    friend = friendRepository.GetFriendById(friendId);
                    friendRepository.DeleteObject(friend, true);
                }
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Message));
        }
        public MainPageViewModel()
        {
            friendRepository = new FriendRepository();
            Friends          = friendRepository.GetAllGrouped();

            //PAGINA 16 DEL PDF AGREGAR EN EL CONSTRUCTOR
        }
Beispiel #5
0
        public HttpResponseMessage GetListMyPaymentsByFriendName(String nameOut)
        {
            PaymentRepository paymentRepository = new PaymentRepository();
            IList <Payment>   paymentList       = paymentRepository.GetPaymentListByFriendName(nameOut);

            if (paymentList != null)
            {
                List <PaymentViewModel> listPaymentView = new List <PaymentViewModel>();
                FriendRepository        friendName      = new FriendRepository();

                foreach (dynamic item in paymentList)
                {
                    listPaymentView.Add(new PaymentViewModel
                    {
                        Id            = item.Id,
                        Value         = item.Value.ToString(),
                        Date          = Convert.ToString(item.Date),
                        FriendNameIn  = friendName.GetFriendNameById(item.FriendIdIn).Trim(),
                        FriendNameOut = friendName.GetFriendNameById(item.FriendIdOut).Trim()
                    });
                }
                return(Request.CreateResponse(HttpStatusCode.OK, listPaymentView.ToArray()));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find payment."));
        }
Beispiel #6
0
        public PagedResult <GameLoan> FindGameLoansByDate([FromQuery] int page, [FromQuery] int pageSize, [FromQuery] DateTime?initialDate = null, [FromQuery] DateTime?finalDate = null)
        {
            var currentUser = UserService.GetCurrentUser();
            var friend      = FriendRepository.FindFriendByUserId(currentUser.UserId);

            return(GameLoanService.FindUserGameLoansByDate(page, pageSize, initialDate, finalDate, friend.Id));
        }
        public CategoryApiController()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            friendCategoryRepository = new FriendCategoryRepository(context);
            friendRepository         = new FriendRepository(context);
        }
Beispiel #8
0
        public HttpResponseMessage GetListMyDebtsByFriendName(String nameOut)
        {
            DebtRepository debtRepository = new DebtRepository();
            IList <Debt>   listDebt       = debtRepository.GetListMyDebtsByFriendName(nameOut);

            if (listDebt != null)
            {
                List <DebtViewModel> listDebtView = new List <DebtViewModel>();
                FriendRepository     friendName   = new FriendRepository();

                foreach (dynamic item in listDebt)
                {
                    listDebtView.Add(new DebtViewModel
                    {
                        Id            = item.Id,
                        Date          = Convert.ToString(item.Date),
                        Description   = item.Description,
                        Value         = item.Value.ToString(),
                        FriendNameIn  = friendName.GetFriendNameById(item.FriendIdIn).Trim(),
                        FriendNameOut = friendName.GetFriendNameById(item.FriendIdOut).Trim()
                    });
                }
                return(Request.CreateResponse(HttpStatusCode.OK, listDebtView.ToArray()));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
        }
        public HttpResponseMessage CreateFriend([FromBody] FriendViewModel friendAttribute)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            var Message = validates.ValidateFriend(friendAttribute);

            if (Message == String.Empty)
            {
                if (friendRepository == null)
                {
                    FriendRepository friendRepository = new FriendRepository();
                }

                Friend friend = new Friend();
                friend.Name = friendAttribute.Name.Trim();
                friend.Sex  = friendAttribute.Sex;
                friend.Age  = Convert.ToInt32(friendAttribute.Age);

                Boolean sucess = friendRepository.Insert(friend);

                if (sucess)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create()));
                }
            }
            return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
        }
Beispiel #10
0
        public RedirectToRouteResult Create(FriendViewModel friend)
        {
            var repository = new FriendRepository();

            repository.InsertFriends(friend);
            return(RedirectToAction("Index"));
        }
Beispiel #11
0
 public IPostResponse Insert(IFriend friend)
 {
     using (FriendRepository repo = new FriendRepository())
     {
         return(repo.Insert(friend));
     }
 }
Beispiel #12
0
        public IActionResult GetToken([FromBody] Auth auth)
        {
            if (string.IsNullOrEmpty(auth.Email))
            {
                return(BadRequest());
            }

            Friend friend = FriendRepository.Find(auth.Email);

            if (friend == null)
            {
                return(BadRequest());
            }

            if (auth.Password != friend.Password)
            {
                return(BadRequest());
            }

            string token = GenerateToken(friend.Id);



            return(Ok(new { Token = token }));
        }
        //
        // GET: /Account/ChangeUserData

        public ActionResult Accept(string id)
        {
            String userID   = User.Identity.GetUserId();
            String senderID = id;

            //Create new repositories
            FriendRequestRepository   friendRequestRepository   = new FriendRequestRepository(context);
            FriendRepository          friendRepository          = new FriendRepository(context);
            ApplicationUserRepository applicationUserRepository = new ApplicationUserRepository(context);

            ApplicationUser sendingUser   = applicationUserRepository.GetAll().Find(x => x.Id == senderID);
            ApplicationUser recievingUser = applicationUserRepository.GetAll().Find(x => x.Id == userID);

            var friend = new Friend
            {
                User1 = recievingUser,
                User2 = sendingUser
            };

            friendRepository.Add(friend);
            friendRepository.Save();


            var removeList = context.FriendRequests.Where(x => (x.FriendReceiver.Id == userID && x.FriendSender.Id == senderID) ||
                                                          (x.FriendReceiver.Id == senderID && x.FriendSender.Id == userID));

            foreach (var item in removeList)
            {
                friendRequestRepository.Items.Remove(item);
            }

            friendRequestRepository.Save();

            return(RedirectToAction("FriendRequest"));
        }
Beispiel #14
0
        public async Task <ActionResult> Edit(int id = 0)
        {
            if (id > 0)
            {
                using (var context = new S2GamesContext())
                {
                    var repository = new FriendRepository(context);

                    var friend = await repository.GetByIdAsync(id, ConnectedId);

                    if (friend == null)
                    {
                        return(HttpNotFound());
                    }

                    context.Dispose();
                    return(View(friend));
                }
            }
            else
            {
                return(View(new Friend {
                    UserId = ConnectedId
                }));
            }
        }
        public List <String> GetFriends(Guid userID, String prefix)
        {
            IEnumerable <Friend> friendsList = FriendRepository.GetUserFriends(userID);
            List <String>        friends     = friendsList
                                               .Select(x => x.ID.ToString()).ToList();

            return(friends);
        }
Beispiel #16
0
        public FriendRequestController() //konstruktor ska alltid se ut såhär
        {
            ApplicationDbContext context = new ApplicationDbContext();

            AddFriendRepository = new AddFriendRepository(context);
            UserRepository      = new UserRepository(context);
            FriendRepository    = new FriendRepository(context);
        }
Beispiel #17
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            _accountRepository = new AccountRepository(db);
            _gameRepository    = new GameRepository(db);
            _friendRepository  = new FriendRepository(db);
        }
Beispiel #18
0
 public Friend Save(Friend friend)
 {
     Model.CheckModel(friend);
     friend.Validate();
     UserService.CreateUserFromFriend(friend);
     FriendRepository.Save(friend);
     return(friend);
 }
Beispiel #19
0
        public ActionResult AcceptFriendConfirmed(int id)
        {
            FriendRepository friendRepository = new FriendRepository();

            friendRepository.AcceptFriendshipRequest(CurrentAccountID, id);

            return(RedirectToAction("Index", "Friend", new { id = CurrentAccountID }));
        }
Beispiel #20
0
        public ActionResult DeleteFriendConfirmed(int id)
        {
            FriendRepository friendRepository = new FriendRepository();

            friendRepository.RemoveFriendship(CurrentAccountID, id);

            return(RedirectToAction("Index", "Friend", new { id = CurrentAccountID }));
        }
Beispiel #21
0
        public ListViewViewModel()
        {
            FriendRepository repository = new FriendRepository();

            Friends = repository.GetAll().ToList();

            FriendsObservableCollection = repository.GetAllGrouped();
        }
        public UsersController()
        {
            ApplicationDbContext applicationDbContext = new ApplicationDbContext();

            userRepository   = new UserRepository(applicationDbContext);
            postRepository   = new PostRepository(applicationDbContext);
            friendRepository = new FriendRepository(applicationDbContext);
        }
Beispiel #23
0
        public FriendsController()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            userRepository    = new UserRepository(context);
            requestRepository = new RequestRepository(context);
            friendRepository  = new FriendRepository(context);
        }
        public ActionResult DeleteFriendConfirmed(int firstID, int secondID)
        {
            FriendRepository _friendRepository = new FriendRepository();

            _friendRepository.RemoveFriendship(firstID, secondID);

            return(RedirectToAction("Friends"));
        }
        private async Task Search()
        {
            repository = new FriendRepository();

            var lstFriends = repository.GetAllByFirstLetter(Filter);

            await Friends = ObservableCollection <Grouping <string, Friend> >(lstFriends);
        }
        // Initalize Method used for all tests
        public PersonRepositoryTests(DatabaseFixture fixture)
        {
            this.fixture = fixture;

            _personRepository = new PersonRepository(fixture.dbContext);
            _bookRepository   = new BookRepository(fixture.dbContext);
            _FriendRepository = new FriendRepository(fixture.dbContext);
        }
        public FriendController() //konstruktor ska alltid se ut såhär
        {
            ApplicationDbContext context = new ApplicationDbContext();

            userRepository      = new UserRepository(context);
            addFriendRepository = new AddFriendRepository(context);
            friendRepository    = new FriendRepository(context);
            postRepository      = new PostRepository(context);
        }
Beispiel #28
0
        public HttpResponseMessage UpdateDebt([FromBody] DebtViewModel debtAttribute, [FromUri] int debtId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateUpdateDebt(debtAttribute, debtId);

            if (Message == String.Empty)
            {
                Debt             debt       = new Debt();
                FriendRepository friendName = new FriendRepository();
                Boolean          sucess;

                if (debtRepository == null)
                {
                    DebtRepository debtRepository = new DebtRepository();

                    debt = debtRepository.GetDebtById(debtId);

                    if (debt != null)
                    {
                        debtAttribute.Id = debtId;
                        debt.Value       = Convert.ToDecimal(debtAttribute.Value);
                        debt.Date        = Convert.ToDateTime(debtAttribute.Date);
                        debt.Description = debtAttribute.Description;
                        debt.FriendIdIn  = friendName.GetFriendIdByName(debtAttribute.FriendNameIn);
                        debt.FriendIdOut = friendName.GetFriendIdByName(debtAttribute.FriendNameOut);

                        sucess = debtRepository.Update(debt, debtId);

                        if (sucess)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, debtAttribute));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not update debt."));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
                    }
                }
                else
                {
                    debt   = debtRepository.GetDebtById(debtId);
                    sucess = debtRepository.Update(debt, debtId);

                    if (sucess)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, debt));
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
            }
        }
 public MainPageViewModel(INavigation navigation)
 {
     repository        = new FriendRepository();
     Friends           = repository.GetAllGrouped();
     Navigation        = navigation;
     AddFriendCommand  = new Command(async() => await AddFriend());
     SearchCommand     = new Command(async() => await Search());
     ITemTappedCommand = new Command(async() => await NavigateToEditFriendView());
 }
        private IEnumerable <NewFeeds> GetNewFeeds(string userId)
        {
            IFriendRepository friendRepository = new FriendRepository(this._db);
            var friendListId = friendRepository.GetFriendListId(userId);

            return(this._db.NewFeeds.Where(n => friendListId.Contains(n.UserId))
                   .OrderByDescending(n => n.NewFeedId)
                   .Take(5));
        }