示例#1
0
        public string UserRewardAndCommentAwarded(RewardUser rewardUser)
        {
            PostSolution solution = _context.PostSolutions.Include(x => x.Post).Where(x => x.ID.Equals(rewardUser.SolutionID)).FirstOrDefault();

            solution.isAwarded = 1; //comment awarded!!!



            int userID = solution.UserID;

            UserData user = _context.UserDatas.Where(x => x.ID.Equals(userID)).FirstOrDefault();

            user.Eko += rewardUser.Prize;

            _context.UserDatas.Update(user);
            _context.PostSolutions.Update(solution);

            Notification notify = new Notification();


            notify.UserID             = solution.UserID;
            notify.TypeOfNotification = 5; //myRewardedSolution = 5
            notify.isRead             = false;
            if (solution.UserType == 1)    // user 1, org 2
            {
                var userPom = _context.UserDatas.FirstOrDefault(x => x.ID == solution.UserID);


                notify.Title = "Vaše resenje " + solution.Text + " je nagrađeno ";
                //notify.Message = "Vase resenje " + solution.Text + " je nagradjeno ";
                notify.Message = DateTime.Now.ToString();
                notify.UserNotificationMakerPhoto = userPom.Photo;
            }
            else if (solution.UserType == 2)
            {
                var org = _context.Organisations.FirstOrDefault(x => x.ID == solution.UserID);

                notify.Title = "Vaše resenje " + solution.Text + " je nagrađeno ";
                //notify.Message = "Vase resenje " + solution.Text + " je nagradjeno ";
                notify.Message = DateTime.Now.ToString();
                notify.UserNotificationMakerPhoto = org.ImagePath;
            }
            notify.NewThingID = solution.ID;
            notify.UserNotificationMakerID = solution.Post.UserDataID;

            notify.NotificationForID = solution.Post.ID;

            if (notify.UserID != notify.UserNotificationMakerID && solution.UserType == 1)
            {
                _context.Notifications.Add(notify);
            }
            if (solution.UserType == 2)
            {
                _context.Notifications.Add(notify);
            }

            _context.SaveChanges();

            return("true");
        }
示例#2
0
        public bool AddPostSolution(PostSolution ps)
        {
            try
            {
                _context.PostSolutions.Add(ps);
                _context.SaveChanges();

                Notification notify   = new Notification();
                var          solution = _context.PostSolutions.Include(x => x.Post).FirstOrDefault(x => x.ID == ps.ID);


                notify.UserID             = solution.Post.UserDataID;
                notify.TypeOfNotification = 4; //newSolution = 4
                notify.isRead             = false;
                if (solution.UserType == 1)    // user 1, org 2
                {
                    var user = _context.UserDatas.FirstOrDefault(x => x.ID == solution.UserID);
                    notify.Title = user.Name + " " + user.Lastname + " je dodao/la novo rešenje na Vašoj objavi " + solution.Post.Title;
                    //notify.Message = user.Name + " " + user.Lastname + " je dodao/la novo resenje na vasoj objavi " + solution.Post.Title;
                    notify.Message = DateTime.Now.ToString();
                    notify.UserNotificationMakerPhoto = user.Photo;
                }
                else if (solution.UserType == 2)
                {
                    var org = _context.Organisations.FirstOrDefault(x => x.ID == solution.UserID);

                    notify.Title = org.Name + " je dodao/la novo rešenje na Vašoj objavi " + solution.Post.Title;
                    //notify.Message = org.Name + " je dodao/la novo resenje na vasoj objavi " + solution.Post.Title;
                    notify.Message = DateTime.Now.ToString();
                    notify.UserNotificationMakerPhoto = org.ImagePath;
                }
                notify.NewThingID = solution.ID;
                notify.UserNotificationMakerID = solution.UserID;

                notify.NotificationForID = solution.Post.ID;

                if (notify.UserID != notify.UserNotificationMakerID && solution.UserType == 1)
                {
                    _context.Notifications.Add(notify);
                }
                if (solution.UserType == 2)
                {
                    _context.Notifications.Add(notify);
                }

                _context.SaveChanges();
                return(true);

                //newSolution = 4
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#3
0
 public bool AddPostSolution(PostSolution ps)
 {
     return(_IPostsUI.AddPostSolution(ps));
 }