// GET: VacationRequests
        public async Task <ViewResult> Index()
        {
            var applicationDbContext = _context.VacationRequest.Include(v => v.User).Where(v => v.Deleted == false).AsQueryable();

            if (!(await usermanager.IsInRoleAsync(await usermanager.GetUserAsync(User), "الادارة")))
            {
                var userid = usermanager.GetUserId(User);
                applicationDbContext = applicationDbContext.Where(c => c.UserID == userid);
            }
            return(View(applicationDbContext));
        }
        public async Task <IActionResult> Create([Bind("FullName,AmountOfMoneyNumber,AmountOfMoneyText,Reason,OnAccount,ReceivedFrom,Currency,ID,CreatedDate,UpdatedDate,UserID,Deleted")] Receipts receipts)
        {
            if (ModelState.IsValid)
            {
                var datetime = DateTime.UtcNow;
                receipts.ID          = Guid.NewGuid();
                receipts.CreatedDate = datetime;
                receipts.UpdatedDate = datetime;
                receipts.UserID      = usermanager.GetUserId(User);
                _context.Add(receipts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(receipts));
        }
        public async Task <IActionResult> Create([Bind("LicenseHolderName,IdentificationNumber,CraftOrIndustryType,ClassifiedInTail,Address,Ends,LicenseFee,VoucherNumber,ID,CreatedDate,UpdatedDate,UserID,Deleted")] CraftAndIndustryLicense craftAndIndustryLicense)
        {
            if (ModelState.IsValid)
            {
                var datetime = DateTime.UtcNow;
                craftAndIndustryLicense.ID          = Guid.NewGuid();
                craftAndIndustryLicense.CreatedDate = datetime;
                craftAndIndustryLicense.UpdatedDate = datetime;
                craftAndIndustryLicense.UserID      = usermanager.GetUserId(User);
                _context.Add(craftAndIndustryLicense);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(craftAndIndustryLicense));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("FullName,PhoneNumber,IdentificationNumber,AreaName,FullAddress,ComplaintType,SubjectComplaint,ID,CreatedDate,UpdatedDate,UserID,Deleted")] ComplaintForm complaintForm)
        {
            if (ModelState.IsValid)
            {
                var datetime = DateTime.UtcNow;
                complaintForm.ID          = Guid.NewGuid();
                complaintForm.CreatedDate = datetime;
                complaintForm.UpdatedDate = datetime;
                complaintForm.UserID      = usermanager.GetUserId(User);
                _context.Add(complaintForm);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(complaintForm));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Name,Location,PhoneNumber,BasinNumber,PieceNumber,WaterOfficialSuggestions,MunicipalityDecision,ID,CreatedDate,UpdatedDate,UserID,Deleted")] WaterMeterSubscriptionRequest waterMeterSubscriptionRequest)
        {
            if (ModelState.IsValid)
            {
                var datetime = DateTime.UtcNow;
                waterMeterSubscriptionRequest.ID          = Guid.NewGuid();
                waterMeterSubscriptionRequest.CreatedDate = datetime;
                waterMeterSubscriptionRequest.UpdatedDate = datetime;
                waterMeterSubscriptionRequest.UserID      = usermanager.GetUserId(User);
                _context.Add(waterMeterSubscriptionRequest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(waterMeterSubscriptionRequest));
        }
        public IActionResult Profile(string id)
        {
            //var userid = id;
            //if (userid == null)
            //    userid = _userManager.GetUserId(User);
            //var user = context.Users.Find(userid);
            //if (userid == null)
            //    return RedirectToAction("Home");
            //return View(user);

            //--------------------------------------

            //Profile info
            if (id == null)
            {
                id = _userManager.GetUserId(User);
            }
            var userFromDb = context.Users.Include(u => u.Posts).SingleOrDefault(u => u.Id == id);
            var userVM     = new UserViewModel()
            {
                Nickname  = userFromDb.Nickname,
                Bio       = userFromDb.Bio,
                BirthDate = userFromDb.BirthDate,
                Gender    = userFromDb.Gender,
                Image     = userFromDb.Image,
                Email     = userFromDb.Email,
                UserId    = userFromDb.Id,
            };

            IEnumerable <Post> postsList = context.Posts.Where(p => p.IsDeleted == false);
            var postVMLst = new List <PostsViewModel>();

            foreach (var post in postsList)
            {
                //var currentUserId = _userManager.GetUserId(User);
                if (post.UserId == id)
                {
                    var postVM = new PostsViewModel();
                    postVM.Content     = post.Content;
                    postVM.IsDeleted   = post.IsDeleted;
                    postVM.PostId      = post.Id;
                    postVM.UserId      = post.UserId;
                    postVM.PostingDate = post.PostingDate;

                    IEnumerable <UserLikesPost>      likesList    = context.UserLikesPosts.Where(l => l.PostId == post.Id && l.IsLiked == true);
                    IEnumerable <UserCommentsOnPost> commentsList = context.UserCommentsOnPosts.Where(c => c.PostId == post.Id && c.IsDeleted == false);

                    var likesVMLst    = new List <LikesViewModel>();
                    var commentsVMLst = new List <CommentsViewModel>();

                    foreach (var like in likesList)
                    {
                        var likeVM = new LikesViewModel();
                        likeVM.UserId  = like.UserId;
                        likeVM.PostId  = like.PostId;
                        likeVM.IsLiked = like.IsLiked;
                        likesVMLst.Add(likeVM);
                    }
                    postVM.likesVMList = likesVMLst;

                    foreach (var comment in commentsList)
                    {
                        var commentVM = new CommentsViewModel();
                        commentVM.Content   = comment.Content;
                        commentVM.UserId    = comment.UserId;
                        commentVM.IsDeleted = comment.IsDeleted;
                        commentVM.PostId    = comment.PostId;
                        commentVM.CommentId = comment.CommentId;
                        commentsVMLst.Add(commentVM);
                    }
                    postVM.commentsVMList = commentsVMLst;


                    postVMLst.Add(postVM);
                }
            }

            userVM.Posts = postVMLst;

            //if (userFromDb.Posts != null)
            //    foreach (var item in userFromDb.Posts)
            //    {
            //        userVM.Posts.Add(new PostsViewModel()
            //        {
            //            Content = item.Content,
            //            IsDeleted = item.IsDeleted,
            //            PostingDate = item.PostingDate,
            //            UserId = id,
            //            PostId = item.Id
            //        });
            //    }
            //Get friends of the user
            var friendships = context.UserHasFriends.Where(f => f.UserId == id || f.FriendId == id).ToList();

            if (friendships.Count > 0)
            {
                foreach (var friendship in friendships)
                {
                    if (friendship.Status != FriendRequestStatus.NotFriend)
                    {
                        var trueFriendId     = "";
                        var friendshipStatus = friendship.Status;

                        if (friendship.FriendId == id)
                        {
                            trueFriendId = friendship.UserId;
                            if (friendship.Status == FriendRequestStatus.SentAndPending)
                            {
                                friendshipStatus = FriendRequestStatus.ReceivedAndPending;
                            }
                            else if (friendship.Status == FriendRequestStatus.ReceivedAndPending)
                            {
                                friendshipStatus = FriendRequestStatus.SentAndPending;
                            }
                        }
                        else if (friendship.UserId == id)
                        {
                            trueFriendId = friendship.FriendId;
                        }
                        //var friendFromDb = context.Users.Find(friendship.FriendId ?? friendship.UserId);
                        var friendFromDb = context.Users.Find(trueFriendId);

                        userVM.Friends.Add(new FriendsViewModel()
                        {
                            FriendId = friendFromDb.Id,
                            Nickname = friendFromDb.Nickname,
                            Email    = friendFromDb.Email,
                            Bio      = friendFromDb.Bio,
                            Gender   = friendFromDb.Gender,
                            Image    = friendFromDb.Image,
                            Status   = friendshipStatus
                        });
                    }
                }
            }
            //else
            //    userVM.Status = FriendRequestStatus.NotFriend;
            return(View(userVM));
        }
        public IActionResult Index(int flag)
        {
            ViewBag.flag = flag;
            //return View(context.Posts.OrderByDescending(p => p.PostingDate).ToList());

            var id = _userManager.GetUserId(User);

            var userFromDb = context.Users.Include(u => u.Posts).SingleOrDefault(u => u.Id == id);
            var userVM     = new UserViewModel()
            {
                Nickname  = userFromDb.Nickname,
                Bio       = userFromDb.Bio,
                BirthDate = userFromDb.BirthDate,
                Gender    = userFromDb.Gender,
                Image     = userFromDb.Image,
                Email     = userFromDb.Email,
                UserId    = userFromDb.Id,
            };

            IEnumerable <Post> postsList = context.Posts.Where(p => p.IsDeleted == false);
            var postVMLst = new List <PostsViewModel>();

            foreach (var post in postsList)
            {
                var currentUserId = _userManager.GetUserId(User);
                var isAFriend     = context.UserHasFriends.FirstOrDefault(u => (u.UserId == post.UserId || u.FriendId == post.UserId) && (u.UserId == currentUserId || u.FriendId == currentUserId) && u.Status == FriendRequestStatus.Friend);
                if (isAFriend != null || post.UserId == currentUserId)
                {
                    var postVM = new PostsViewModel();
                    postVM.Content     = post.Content;
                    postVM.IsDeleted   = post.IsDeleted;
                    postVM.PostId      = post.Id;
                    postVM.UserId      = post.UserId;
                    postVM.PostingDate = post.PostingDate;

                    IEnumerable <UserLikesPost>      likesList    = context.UserLikesPosts.Where(l => l.PostId == post.Id && l.IsLiked == true);
                    IEnumerable <UserCommentsOnPost> commentsList = context.UserCommentsOnPosts.Where(c => c.PostId == post.Id && c.IsDeleted == false);

                    var likesVMLst    = new List <LikesViewModel>();
                    var commentsVMLst = new List <CommentsViewModel>();

                    foreach (var like in likesList)
                    {
                        var likeVM = new LikesViewModel();
                        likeVM.UserId  = like.UserId;
                        likeVM.PostId  = like.PostId;
                        likeVM.IsLiked = like.IsLiked;
                        likesVMLst.Add(likeVM);
                    }
                    postVM.likesVMList = likesVMLst;

                    foreach (var comment in commentsList)
                    {
                        var commentVM = new CommentsViewModel();
                        commentVM.Content   = comment.Content;
                        commentVM.UserId    = comment.UserId;
                        commentVM.IsDeleted = comment.IsDeleted;
                        commentVM.PostId    = comment.PostId;
                        commentVM.CommentId = comment.CommentId;
                        commentsVMLst.Add(commentVM);
                    }
                    postVM.commentsVMList = commentsVMLst;


                    postVMLst.Add(postVM);
                }
            }

            userVM.Posts = postVMLst;

            //postVMLst.OrderByDescending(p => p.PostingDate)
            return(View(userVM));
        }
        public IActionResult Profile(string id)
        {
            #region Commented
            //var userid = id;
            //if (userid == null)
            //    userid = _userManager.GetUserId(User);
            //var user = context.Users.Find(userid);
            //if (userid == null)
            //    return RedirectToAction("Home");
            //return View(user);

            //--------------------------------------
            #endregion

            #region Profile info
            if (id == null)
            {
                id = _userManager.GetUserId(User);
            }
            var userFromDb = context.Users.Include(u => u.Posts).SingleOrDefault(u => u.Id == id);
            var userVM     = new UserViewModel()
            {
                Nickname    = userFromDb.Nickname,
                Bio         = userFromDb.Bio,
                BirthDate   = userFromDb.BirthDate,
                Gender      = userFromDb.Gender,
                Image       = userFromDb.Image,
                Email       = userFromDb.Email,
                UserId      = userFromDb.Id,
                isBlocked   = userFromDb.isBlocked,
                PhoneNumber = userFromDb.PhoneNumber
            };
            #endregion

            IEnumerable <Post> postsList = context.Posts.Where(p => p.IsDeleted == false);
            var postVMLst = new List <PostsViewModel>();
            #region Getting all the posts with their likes and comments
            if (postsList != null)
            {
                foreach (var post in postsList)
                {
                    //var currentUserId = _userManager.GetUserId(User);
                    if (post.UserId == id)
                    {
                        //Posts
                        var postVM = new PostsViewModel()
                        {
                            Content     = post.Content,
                            IsDeleted   = post.IsDeleted,
                            PostId      = post.Id,
                            UserId      = post.UserId,
                            PostingDate = post.PostingDate,
                            Image       = post.Image
                        };
                        IEnumerable <UserLikesPost>      likesList    = context.UserLikesPosts.Where(l => l.PostId == post.Id && l.IsLiked == true);
                        IEnumerable <UserCommentsOnPost> commentsList = context.UserCommentsOnPosts.Where(c => c.PostId == post.Id && c.IsDeleted == false);
                        var likesVMLst    = new List <LikesViewModel>();
                        var commentsVMLst = new List <CommentsViewModel>();
                        //Likes
                        foreach (var like in likesList)
                        {
                            var likeVM = new LikesViewModel();
                            likeVM.UserId  = like.UserId;
                            likeVM.PostId  = like.PostId;
                            likeVM.IsLiked = like.IsLiked;
                            likesVMLst.Add(likeVM);
                        }
                        postVM.likesVMList = likesVMLst;
                        //Comments
                        foreach (var comment in commentsList)
                        {
                            var commentVM = new CommentsViewModel();
                            commentVM.Content   = comment.Content;
                            commentVM.UserId    = comment.UserId;
                            commentVM.IsDeleted = comment.IsDeleted;
                            commentVM.PostId    = comment.PostId;
                            commentVM.CommentId = comment.CommentId;
                            commentsVMLst.Add(commentVM);
                        }
                        postVM.commentsVMList = commentsVMLst;
                        postVMLst.Add(postVM);
                    }
                }
            }
            userVM.Posts = postVMLst.OrderByDescending(p => p.PostingDate).ToList();
            #endregion

            #region Getting friends of the current user
            if (id == _userManager.GetUserId(User)) //Friends list in the current user profile
            {
                var friendships = context.UserHasFriends.Where(f => f.UserId == _userManager.GetUserId(User) || f.FriendId == _userManager.GetUserId(User) && f.Status != FriendRequestStatus.NotFriend).ToList();
                if (friendships.Count > 0)
                {
                    foreach (var friendship in friendships)
                    {
                        var trueFriendId     = string.Empty; //reciever user id
                        var friendshipStatus = friendship.Status;

                        if (friendship.FriendId == _userManager.GetUserId(User))
                        {
                            trueFriendId = friendship.UserId;
                        }
                        else if (friendship.UserId == _userManager.GetUserId(User))
                        {
                            trueFriendId = friendship.FriendId;
                        }

                        var friendFromDb = context.Users.Find(trueFriendId); // Friend that I have sent to him or recieved from him (Not current user)
                        if (friendFromDb != null)
                        {
                            userVM.Friends.Add(new FriendsViewModel()
                            {
                                FriendId   = friendFromDb.Id,
                                Nickname   = friendFromDb.Nickname,
                                Email      = friendFromDb.Email,
                                Bio        = friendFromDb.Bio,
                                Gender     = friendFromDb.Gender,
                                Image      = friendFromDb.Image,
                                Status     = friendshipStatus,
                                SenderId   = friendship.UserId,
                                RecieverId = friendship.FriendId
                            });
                        }

                        userVM.SenderId   = friendship.UserId;
                        userVM.RecieverId = friendship.FriendId;
                    }
                }
            }
            else //friendship between the current user and the profile owner
            {
                var friendship = context.UserHasFriends.FirstOrDefault(f => ((f.UserId == _userManager.GetUserId(User) && f.FriendId == id) || (f.FriendId == _userManager.GetUserId(User) && f.UserId == id)) && f.Status != FriendRequestStatus.NotFriend);
                if (friendship != null)                  //there is a friendship between current user and the profile owner
                {
                    var trueFriendId     = string.Empty; //reciever user id
                    var friendshipStatus = friendship.Status;

                    if (friendship.FriendId == _userManager.GetUserId(User))
                    {
                        trueFriendId = friendship.UserId;
                    }
                    else if (friendship.UserId == _userManager.GetUserId(User))
                    {
                        trueFriendId = friendship.FriendId;
                    }

                    var friendFromDb = context.Users.Find(trueFriendId); // Friend that I have sent to him or recieved from him (Not current user)
                    if (friendFromDb != null)
                    {
                        userVM.Friends.Add(new FriendsViewModel()
                        {
                            FriendId   = friendFromDb.Id,
                            Nickname   = friendFromDb.Nickname,
                            Email      = friendFromDb.Email,
                            Bio        = friendFromDb.Bio,
                            Gender     = friendFromDb.Gender,
                            Image      = friendFromDb.Image,
                            Status     = friendshipStatus,
                            SenderId   = friendship.UserId,
                            RecieverId = friendship.FriendId
                        });
                    }

                    userVM.SenderId   = friendship.UserId;
                    userVM.RecieverId = friendship.FriendId;
                }
            }
            #endregion
            return(View(userVM));
        }