public ActionResult ConfirmFriendRequest(FriendRequestViewModel friendRequest)
        {
            var rrequestid = EncryptionHelper.Unprotect(friendRequest.request);
            var fRequest   = unitOfWork.FriendshipRequestRepository.GetByID(rrequestid);

            if (fRequest.requestReceiverID == WebSecurity.CurrentUserId)
            {
                Friendship newFriendship = new Friendship();
                newFriendship.userID         = fRequest.requestSenderID;
                newFriendship.friendID       = fRequest.requestReceiverID;
                newFriendship.friendshipDate = DateTime.UtcNow;
                unitOfWork.FriendshipRepository.Insert(newFriendship);
                unitOfWork.FriendshipRequestRepository.Delete(fRequest.requestID);

                unitOfWork.Save();
                NotificationHelper.NotificationInsert(NotificationType.FriendRequestAccept,
                                                      recId: fRequest.requestSenderID,
                                                      elemId: newFriendship.frendshipId,
                                                      data: fRequest.requestReceiverID.ToString());
                unitOfWork.Save();
                return(Json(new {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "AreFriends", null),
                    Message = Resource.Resource.friendRequestConfirmed
                }));
            }
            throw new JsonCustomException(ControllerError.ajaxErrorFriendRequest);
        }
        public ActionResult AddFriend(FriendRequestViewModel friendRequest)
        {
            var  onlineUser      = WebSecurity.CurrentUserId;
            var  requesteruserid = (int)EncryptionHelper.Unprotect(friendRequest.user);
            var  formerRequests  = unitOfWork.FriendshipRequestRepository.Get();
            bool isFormerRequest = formerRequests.Any(u => (u.requestReceiverID == requesteruserid && u.requestSenderID == onlineUser) ||
                                                      (u.requestSenderID == requesteruserid && u.requestReceiverID == onlineUser));

            if (ModelState.IsValid)
            {
                if (!isFormerRequest)
                {
                    FriendRequest newFriendRequest = new FriendRequest();
                    newFriendRequest.message           = friendRequest.message;
                    newFriendRequest.requestSenderID   = onlineUser;
                    newFriendRequest.requestReceiverID = requesteruserid;
                    newFriendRequest.requestDate       = DateTime.UtcNow;

                    unitOfWork.FriendshipRequestRepository.Insert(newFriendRequest);
                    unitOfWork.Save();

                    friendRequest.request = EncryptionHelper.Protect(newFriendRequest.requestID);
                    return(Json(new {
                        Result = RenderPartialViewHelper.RenderPartialView(this, "FRSentBefore", friendRequest),
                        Message = Resource.Resource.friendRequestSent
                    }));
                }
            }
            throw new JsonCustomException(ControllerError.ajaxErrorFriendRequestAdd);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(string ATE, string A)
        {
            NullChecker.NullCheck(new object[] { ATE, A });
            var    ate = EncryptionHelper.Unprotect(ATE);
            var    a   = EncryptionHelper.Unprotect(A);
            Answer answerEntryToEdit = unitOfWork.AnswerRepository.GetByID(EncryptionHelper.Unprotect(ATE));

            if (AuthorizationHelper.isRelevant(answerEntryToEdit.answererID) && ate == a)
            {
                if (TryUpdateModel(answerEntryToEdit, "", new string[] { "answerBody" }))
                {
                    if (!String.IsNullOrWhiteSpace(answerEntryToEdit.answerBody))
                    {
                        unitOfWork.AnswerRepository.Update(answerEntryToEdit);
                        unitOfWork.Save();
                    }
                    UnitOfWork editContext = new UnitOfWork();
                    var        answer      = editContext.AnswerRepository.GetByID(answerEntryToEdit.answerID);
                    return(Json(new
                    {
                        Result = RenderPartialViewHelper.RenderPartialView(this, "AnswerDetailPartial", answer),
                        Message = Resource.Resource.editedSuccessfully
                    }));
                }
                throw new ModelStateException(this.ModelState);
            }
            throw new JsonCustomException(ControllerError.ajaxErrorAnswerEdit);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(string patID, FormCollection formCollection)
        {
            NullChecker.NullCheck(new object[] { patID });

            Patent patentEntryToEdit = unitOfWork.PatentRepository
                                       .GetByID(EncryptionHelper.Unprotect(patID));

            if (!patentEntryToEdit.Inventors.Any(i => AuthorizationHelper.isRelevant(i.UserId)))
            {
                throw new JsonCustomException(ControllerError.ajaxErrorPatentUser);
            }
            if (TryUpdateModel(patentEntryToEdit, "", new string[] { "status", "officeStateID", "patentTitle", "patentTitleEN", "patentNo", "patentURL", "issueDate", "description", "descriptionEN" }))
            {
                unitOfWork.PatentRepository.Update(patentEntryToEdit);
                unitOfWork.Save();
                UnitOfWork newContext   = new UnitOfWork();
                var        editedPatent = newContext.PatentRepository.GetByID(patentEntryToEdit.patentID);
                return(Json(new
                {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "PatentPartial", editedPatent),
                    Message = Resource.Resource.editedSuccessfully
                }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 5
0
        public ActionResult Edit(string eduID, FormCollection formCollection)
        {
            NullChecker.NullCheck(new object[] { eduID });

            Education eduEntryToEdit = unitOfWork.EducationRepository
                                       .GetByID(EncryptionHelper.Unprotect(eduID));

            if (!AuthorizationHelper.isRelevant(eduEntryToEdit.userID))
            {
                throw new JsonCustomException(ControllerError.ajaxErrorEducationUser);
            }

            if (TryUpdateModel(eduEntryToEdit, "", new string[] { "degree", "fieldOfStudy", "fieldOfStudyEN", "school", "schoolEN", "attendDate", "untilDate" }))
            {
                unitOfWork.EducationRepository.Update(eduEntryToEdit);
                unitOfWork.Save();
                UnitOfWork newContext      = new UnitOfWork();
                var        editedEducation = newContext.EducationRepository.GetByID(eduEntryToEdit.educationID);
                return(Json(new
                {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "EducationPartial", editedEducation),
                    Message = Resource.Resource.editedSuccessfully
                }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "title,titleEN,coName,coNameEN,description,descriptionEN,attendDate,untilDate,stateID")] Experience exp, string CoId)
        {
            if (!String.IsNullOrEmpty(CoId))
            {
                ModelState.Remove("coName");
                ModelState.Remove("coNameEN");
            }
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(CoId))
                {
                    var coid = EncryptionHelper.Unprotect(CoId);
                    var companyToExperience = unitOfWork.NotExpiredCompanyRepository.GetByID(coid);
                    exp.coName   = companyToExperience.coName;
                    exp.coNameEN = companyToExperience.coNameEN;
                    exp.CoId     = coid;
                }

                exp.userID = WebSecurity.CurrentUserId;
                unitOfWork.ExperienceRepository.Insert(exp);
                unitOfWork.Save();
                FeedHelper.FeedInsert(FeedType.Experience,
                                      exp.experienceID,
                                      exp.userID
                                      );
                UnitOfWork newContext    = new UnitOfWork();
                var        newExperience = newContext.ExperienceRepository.GetByID(exp.experienceID);
                return(Json(new
                {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "ExperiencePartial", newExperience),
                    Message = Resource.Resource.createdSuccessfully
                }));
            }
            throw new ModelStateException(this.ModelState);
        }
        public ActionResult IgnoreFriendRequest(FriendRequestViewModel friendRequest)
        {
            var requestid      = EncryptionHelper.Unprotect(friendRequest.request);
            var requstToIgnore = unitOfWork.FriendshipRequestRepository.GetByID(requestid);

            requstToIgnore.ignore = true;
            unitOfWork.FriendshipRequestRepository.Update(requstToIgnore);
            unitOfWork.Save();
            return(Json(new
            {
                Success = true,
                Result = RenderPartialViewHelper.RenderPartialView(this, "AreFriends", null),
                Message = Resource.Resource.friendRequestIgnore
            }));
        }
        public ActionResult DenyFriendRequest(FriendRequestViewModel friendRequest)
        {
            var requestid = EncryptionHelper.Unprotect(friendRequest.request);

            unitOfWork.FriendshipRequestRepository.Delete(requestid);
            unitOfWork.Save();

            friendRequest.message = null;
            friendRequest.request = null;
            return(Json(new
            {
                Success = true,
                Result = RenderPartialViewHelper.RenderPartialView(this, "NoFRBefore", friendRequest),
                Message = Resource.Resource.friendRequestDenied
            }));
        }
Ejemplo n.º 9
0
 public ActionResult Create([Bind(Include = "degree,fieldOfStudy,fieldOfStudyEN,school,schoolEN,attendDate,untilDate")] Education edu)
 {
     if (ModelState.IsValid)
     {
         edu.userID = WebSecurity.CurrentUserId;
         unitOfWork.EducationRepository.Insert(edu);
         unitOfWork.Save();
         UnitOfWork newContext   = new UnitOfWork();
         var        newEducation = newContext.EducationRepository.GetByID(edu.educationID);
         return(Json(new
         {
             Result = RenderPartialViewHelper.RenderPartialView(this, "EducationPartial", newEducation),
             Message = Resource.Resource.createdSuccessfully
         }));
     }
     throw new ModelStateException(this.ModelState);
 }
Ejemplo n.º 10
0
        public ActionResult CancelFriendRequest(FriendRequestViewModel friendRequest)
        {
            var requestid         = EncryptionHelper.Unprotect(friendRequest.request);
            var sentFriendRequest = unitOfWork.FriendshipRequestRepository.GetByID(requestid);

            if (sentFriendRequest.requestSenderID == WebSecurity.CurrentUserId)
            {
                unitOfWork.FriendshipRequestRepository.Delete(requestid);
                unitOfWork.Save();
                friendRequest.message = null;
                friendRequest.request = null;
                return(Json(new {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "NoFRBefore", friendRequest),
                    Message = Resource.Resource.friendRequestCanceled
                }));
            }
            throw new JsonCustomException(ControllerError.ajaxErrorFriendRequest);
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Certificator,CertificatorEN,Name,NameEN,licenceNo,certificatorURL,certificationDate")] Certificate cert, string company)
        {
            var companyToadd = unitOfWork.CompanyRepository.GetByID(EncryptionHelper.Unprotect(company));

            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(company))
                {
                    if (companyToadd.Admins.Any(a => AuthorizationHelper.isRelevant(a.UserId)))
                    {
                        cert.coID = EncryptionHelper.Unprotect(company);
                        unitOfWork.CertificateRepository.Insert(cert);
                        unitOfWork.Save();
                        UnitOfWork newContext     = new UnitOfWork();
                        var        newCertificate = newContext.CertificateRepository.GetByID(cert.certID);
                        return(Json(new
                        {
                            Result = RenderPartialViewHelper.RenderPartialView(this, "CertificatePartial", newCertificate),
                            Message = Resource.Resource.createdSuccessfully
                        }));
                    }
                    throw new JsonCustomException(ControllerError.ajaxErrorCertificateCoAdmin);
                }
                else
                {
                    cert.userID = WebSecurity.CurrentUserId;
                    unitOfWork.CertificateRepository.Insert(cert);
                    unitOfWork.Save();
                    FeedHelper.FeedInsert(FeedType.UserCertificate,
                                          cert.certID,
                                          (int)cert.userID
                                          );
                    UnitOfWork newContext     = new UnitOfWork();
                    var        newCertificate = newContext.CertificateRepository.GetByID(cert.certID);
                    return(Json(new
                    {
                        Result = RenderPartialViewHelper.RenderPartialView(this, "CertificatePartial", newCertificate),
                        Message = Resource.Resource.createdSuccessfully
                    }));
                }
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 12
0
        public ActionResult Edit(string CertID, FormCollection formCollection)
        {
            NullChecker.NullCheck(new object[] { CertID });

            Certificate certEntryToEdit = unitOfWork.CertificateRepository.GetByID(EncryptionHelper.Unprotect(CertID));

            if (TryUpdateModel(certEntryToEdit, "", new string[] { "Certificator", "CertificatorEN", "Name", "NameEN", "licenceNo", "certificatorURL", "certificationDate" }))
            {
                if (certEntryToEdit.coID != null)
                {
                    if (certEntryToEdit.Company.Admins.Any(a => AuthorizationHelper.isRelevant(a.UserId)))
                    {
                        unitOfWork.CertificateRepository.Update(certEntryToEdit);
                        unitOfWork.Save();
                        UnitOfWork newContext        = new UnitOfWork();
                        var        editedCertificate = newContext.CertificateRepository.GetByID(certEntryToEdit.certID);
                        return(Json(new
                        {
                            Result = RenderPartialViewHelper.RenderPartialView(this, "CertificatePartial", editedCertificate),
                            Message = Resource.Resource.editedSuccessfully
                        }));
                    }
                    throw new JsonCustomException(ControllerError.ajaxErrorCertificateCoAdmin);
                }
                else
                {
                    if (AuthorizationHelper.isRelevant((int)certEntryToEdit.userID))
                    {
                        unitOfWork.CertificateRepository.Update(certEntryToEdit);
                        unitOfWork.Save();
                        UnitOfWork newContext        = new UnitOfWork();
                        var        editedCertificate = newContext.CertificateRepository.GetByID(certEntryToEdit.certID);
                        return(Json(new
                        {
                            Result = RenderPartialViewHelper.RenderPartialView(this, "CertificatePartial", editedCertificate),
                            Message = Resource.Resource.editedSuccessfully
                        }));
                    }
                    throw new JsonCustomException(ControllerError.ajaxErrorCertificateCoAdmin);
                }
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 13
0
 public ActionResult Create([Bind(Include = "status,officeStateID,patentTitle,patentTitleEN,patentNo,patentURL,issueDate,description,descriptionEN")] Patent pat)
 {
     if (ModelState.IsValid)
     {
         var currentUser = unitOfWork.ActiveUserRepository.GetByID(WebSecurity.CurrentUserId);
         pat.Inventors = new List <ActiveUser>();
         pat.Inventors.Add(currentUser);
         unitOfWork.PatentRepository.Insert(pat);
         unitOfWork.Save();
         UnitOfWork newContext = new UnitOfWork();
         var        newPatent  = newContext.PatentRepository.GetByID(pat.patentID);
         return(Json(new
         {
             Success = true,
             Result = RenderPartialViewHelper.RenderPartialView(this, "PatentPartial", newPatent),
             Message = Resource.Resource.createdSuccessfully
         }));
     }
     throw new ModelStateException(this.ModelState);
 }
Ejemplo n.º 14
0
        public ActionResult UnFriend(string UTU)
        {
            var onlineUserID       = WebSecurity.CurrentUserId;
            var utuid              = EncryptionHelper.Unprotect(UTU);
            var frienshtipToDelete = unitOfWork.FriendshipRepository.Get(f => (f.userID == onlineUserID && f.friendID == utuid) ||
                                                                         (f.friendID == onlineUserID && f.userID == utuid)).Single();

            //delete notifications
            //frienshtipToDelete.Notifications.Select(n => n.notificationID as object).ToList().ForEach(unitOfWork.NotificationRepository.Delete);
            unitOfWork.FriendshipRepository.Delete(frienshtipToDelete.frendshipId);
            unitOfWork.Save();

            FriendRequestViewModel viewmodel = new FriendRequestViewModel();

            viewmodel.user = UTU;
            return(Json(new
            {
                Result = RenderPartialViewHelper.RenderPartialView(this, "NoFRBefore", viewmodel),
                Message = Resource.Resource.friendRemoved
            }));
        }
Ejemplo n.º 15
0
        public ActionResult Edit(FormCollection formCollection, string filesToUpload, string PIN, string P)
        {
            NullChecker.NullCheck(new object[] { PIN, P });

            var  pin             = EncryptionHelper.Unprotect(PIN);
            var  p               = EncryptionHelper.Unprotect(P);
            Post postEntryToEdit = unitOfWOrk.PostRepository.GetByID(pin);

            if (AuthorizationHelper.isRelevant((int)postEntryToEdit.posterUserID) &&
                pin == p)
            {
                if (TryUpdateModel(postEntryToEdit, "", new string[] { "post" }))
                {
                    if (!String.IsNullOrWhiteSpace(postEntryToEdit.post))
                    {
                        unitOfWOrk.PostRepository.Update(postEntryToEdit);
                    }
                    if (!String.IsNullOrWhiteSpace(filesToUpload))
                    {
                        var fileUploadResult = UploadHelper.UpdateUploadedFiles(filesToUpload, postEntryToEdit.image + postEntryToEdit.document, "Post");
                        postEntryToEdit.image    = fileUploadResult.ImagesToUpload;
                        postEntryToEdit.document = fileUploadResult.DocsToUpload;
                    }
                    unitOfWOrk.PostRepository.Update(postEntryToEdit);
                    unitOfWOrk.Save();
                    UnitOfWork editContext = new UnitOfWork();
                    var        post        = editContext.PostRepository.GetByID(postEntryToEdit.postID);
                    return(Json(new
                    {
                        Success = true,
                        Result = RenderPartialViewHelper.RenderPartialView(this, "PostPartial", post),
                        Message = Resource.Resource.editedSuccessfully
                    }));
                }
                throw new ModelStateException(this.ModelState);
            }
            throw new JsonCustomException(ControllerError.ajaxErrorPostEdit);
        }
Ejemplo n.º 16
0
        public ActionResult Edit(string expID, FormCollection formCollection, string CoId)
        {
            NullChecker.NullCheck(new object[] { expID });
            var        expid          = EncryptionHelper.Unprotect(expID);
            Experience expEntryToEdit = unitOfWork.ExperienceRepository
                                        .GetByID(expid);

            if (!AuthorizationHelper.isRelevant(expEntryToEdit.userID))
            {
                throw new JsonCustomException(ControllerError.ajaxErrorEducationUser);
            }
            if (TryUpdateModel(expEntryToEdit, "", new string[] { "title", "titleEN", "coName", "coNameEN", "description", "descriptionEN", "attendDate", "untilDate", "stateID" }))
            {
                if (!String.IsNullOrEmpty(CoId))
                {
                    var coid = EncryptionHelper.Unprotect(CoId);
                    var companyToExperience = unitOfWork.NotExpiredCompanyRepository.GetByID(coid);
                    expEntryToEdit.coName   = companyToExperience.coName;
                    expEntryToEdit.coNameEN = companyToExperience.coNameEN;
                    expEntryToEdit.CoId     = coid;
                }
                else
                {
                    expEntryToEdit.CoId = null;
                }

                unitOfWork.ExperienceRepository.Update(expEntryToEdit);
                unitOfWork.Save();
                UnitOfWork newContext       = new UnitOfWork();
                var        editedExperience = newContext.ExperienceRepository.GetByID(expid);
                return(Json(new
                {
                    Result = RenderPartialViewHelper.RenderPartialView(this, "ExperiencePartial", editedExperience),
                    Message = Resource.Resource.editedSuccessfully
                }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 17
0
        public ActionResult Create([Bind(Include = "answerBody")] Answer answer, int QA)
        {
            if (ModelState.IsValid)
            {
                answer.questionID = QA;
                answer.answererID = WebSecurity.CurrentUserId;
                answer.answerDate = DateTime.UtcNow;
                unitOfWork.AnswerRepository.Insert(answer);
                unitOfWork.Save();

                NotificationHelper.NotificationInsert(NotifType: NotificationType.QuestionAnswer,
                                                      elemId: answer.questionID);
                FeedHelper.FeedInsert(FeedType.Answer,
                                      answer.answerID,
                                      WebSecurity.CurrentUserId
                                      );

                UnitOfWork newAnswer = new UnitOfWork();
                var        nAnswer   = newAnswer.AnswerRepository.GetByID(answer.answerID);
                return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "AnswerPartial", nAnswer) }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 18
0
        //[AjaxRequestOnly]
        //[HostControl]
        public ActionResult CommentInsert([Deserialize] commentVars model, string comment)
        {
            if (!ModelState.IsValid)
            {
                throw new ModelStateException(this.ModelState);
            }
            var reader = unitOfWork.ReaderRepository.GetSPDataReader(
                "CommentInsert",
                new SqlParameter("U", WebSecurity.CurrentUserId),
                new SqlParameter("elemId", model.elemId),
                new SqlParameter("TBL", model.typ.ToString()),
                new SqlParameter("text", comment)
                );

            CommentEach cmt = new CommentEach();

            if (reader.Read())
            {
                cmt.cmtID   = reader.GetInt32(0);
                cmt.comment = reader[1] as string;
                cmt.date    = reader.GetDateTime(2);
                ActiveUser us = new ActiveUser();
                us.UserId         = reader.GetInt32(3);
                us.firstName      = reader[4] as string;
                us.firstNameEN    = reader[5] as string;
                us.lastName       = reader[6] as string;
                us.lastNameEN     = reader[7] as string;
                cmt.CommenterUser = us;

                ViewData["typ"] = model.typ;
            }

            NotificationType notiftyp = NotificationType.PostLike;
            FeedType         feedtyp  = FeedType.PostLike;

            switch (model.typ)
            {
            case CommentType.CommentPost:
                notiftyp = NotificationType.PostComment;
                feedtyp  = FeedType.PostComment;
                break;

            case CommentType.CommentQuestion:
                notiftyp = NotificationType.QuestionComment;
                feedtyp  = FeedType.QuestionComment;
                break;

            case CommentType.CommentAnswer:
                notiftyp = NotificationType.AnswerComment;
                feedtyp  = FeedType.AnswerComment;
                break;

            case CommentType.CommentProduct:
                notiftyp = NotificationType.ProductComment;
                feedtyp  = FeedType.ProductComment;
                break;

            case CommentType.CommentService:
                notiftyp = NotificationType.ServiceComment;
                feedtyp  = FeedType.ServiceComment;
                break;

            case CommentType.CommentGSO:
                notiftyp = NotificationType.SessionOfferComment;
                feedtyp  = FeedType.SessionOfferComment;
                break;
            }
            NotificationHelper.NotificationInsert(notiftyp, elemId: model.elemId);
            FeedHelper.FeedInsert(feedtyp, model.elemId, WebSecurity.CurrentUserId);


            return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "NewInsertedComment", cmt) }));
        }
        public ActionResult Create([Bind(Include = "offer")] GroupSessionOffer offerToInsert, int SsId)
        {
            var group = unitOfWork.GroupSessionRepository.GetByID(SsId).Group;

            if (group.Members.Any(a => a.UserId == WebSecurity.CurrentUserId))
            {
                if (ModelState.IsValid)
                {
                    offerToInsert.offerDate = DateTime.UtcNow;
                    offerToInsert.sessionId = SsId;
                    offerToInsert.offererId = WebSecurity.CurrentUserId;

                    unitOfWork.GroupSessionOfferRepository.Insert(offerToInsert);
                    unitOfWork.Save();

                    return(Json(new { Message = Resource.Resource.createdSuccessfully, Result = RenderPartialViewHelper.RenderPartialView(this, "PartialOffer", offerToInsert) }));
                }
                throw new ModelStateException(this.ModelState);
            }
            throw new JsonCustomException(ControllerError.ajaxError);
        }
Ejemplo n.º 20
0
        public ActionResult LikeCmtInsert([Deserialize(SerializationMode.Encrypted)] likeVars model)
        {
            if (ModelState.IsValid)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    throw new JsonCustomException(ControllerError.ajaxErrorLike);
                }

                List <SqlParameter> prams = new List <SqlParameter>();
                SqlCommand          outputCommand;
                var isAddedP = new SqlParameter("isAdded", SqlDbType.Int, 50);
                isAddedP.Direction = ParameterDirection.Output;
                prams.Add(isAddedP);
                prams.Add(new SqlParameter("U", WebSecurity.CurrentUserId));
                prams.Add(new SqlParameter("elemId", model.elemId));
                prams.Add(new SqlParameter("typ", model.typ));
                var reader = unitOfWork.ReaderRepository.GetSPDataReader("LikeCommentUpdate", prams, out outputCommand);

                IList <int> likersIds = new List <int>();
                while (reader.Read())
                {
                    likersIds.Add(reader.GetInt32(0));
                }
                reader.Close();
                //if ((int)outputCommand.Parameters["isAdded"].Value == 1 && model.typ != LikeType.LikeComment)
                //{
                //    NotificationType notiftyp = NotificationType.PostLike;
                //    FeedType feedtyp = FeedType.PostLike;
                //    switch (model.typ)
                //    {
                //        case LikeType.LikePost:
                //            notiftyp = NotificationType.PostLike;
                //            feedtyp = FeedType.PostLike;
                //            break;
                //        case LikeType.LikeQuestion:
                //            notiftyp = NotificationType.QuestionLike;
                //            feedtyp = FeedType.QuestionLike;
                //            break;
                //        case LikeType.LikeAnswer:
                //            notiftyp = NotificationType.AnswerLike;
                //            feedtyp = FeedType.AnswerLike;
                //            break;
                //        case LikeType.LikeProduct:
                //            notiftyp = NotificationType.ProductLike;
                //            feedtyp = FeedType.ProductLike;
                //            break;
                //        case LikeType.LikeService:
                //            notiftyp = NotificationType.ServiceLike;
                //            feedtyp = FeedType.ServiceLike;
                //            break;
                //        case LikeType.LikeGSO:
                //            notiftyp = NotificationType.SessionOfferLike;
                //            feedtyp = FeedType.SessionOfferLike;
                //            break;
                //    }
                //    NotificationHelper.NotificationInsert(notiftyp, elemId: model.elemId);
                //    FeedHelper.FeedInsert(feedtyp, model.elemId, WebSecurity.CurrentUserId);
                //}

                LikeViewModel finalModel = new LikeViewModel();
                finalModel.prams    = model;
                finalModel.likerIds = likersIds;
                //finalModel.Likes = likes;

                return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Like", finalModel) }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 21
0
        public ActionResult FollowInsert(string company, string store)
        {
            var currentUser = WebSecurity.CurrentUserId;

            if (!String.IsNullOrEmpty(company))
            {
                var coid      = EncryptionHelper.Unprotect(company);
                var following = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid &&
                                                                   f.followerUserID == currentUser).SingleOrDefault();
                if (following != null)
                {
                    unitOfWork.FollowingRepository.Delete(following);
                    unitOfWork.Save();

                    FollowViewModel viewmodel = new FollowViewModel();
                    var             followers = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid);
                    viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser);
                    viewmodel.Followers      = followers.Count();
                    viewmodel.CoId           = coid;
                    return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) }));
                }
                else
                {
                    var newFollow = new Following();
                    newFollow.followedCoID   = coid;
                    newFollow.followerUserID = currentUser;
                    newFollow.followDate     = DateTime.UtcNow;
                    unitOfWork.FollowingRepository.Insert(newFollow);
                    unitOfWork.Save();

                    FollowViewModel viewmodel = new FollowViewModel();
                    var             followers = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid);
                    viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser);
                    viewmodel.Followers      = followers.Count();
                    viewmodel.CoId           = coid;
                    return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) }));
                }
            }
            else if (!String.IsNullOrEmpty(store))
            {
                var stid      = EncryptionHelper.Unprotect(store);
                var following = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid &&
                                                                   f.followerUserID == currentUser).SingleOrDefault();
                if (following != null)
                {
                    unitOfWork.FollowingRepository.Delete(following);
                    unitOfWork.Save();

                    FollowViewModel viewmodel = new FollowViewModel();
                    var             followers = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid);
                    viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser);
                    viewmodel.Followers      = followers.Count();
                    viewmodel.storeId        = stid;
                    return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) }));
                }
                else
                {
                    var newFollow = new Following();
                    newFollow.followedStoreID = stid;
                    newFollow.followerUserID  = currentUser;
                    newFollow.followDate      = DateTime.UtcNow;
                    unitOfWork.FollowingRepository.Insert(newFollow);
                    unitOfWork.Save();

                    FollowViewModel viewmodel = new FollowViewModel();
                    var             followers = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid);
                    viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser);
                    viewmodel.Followers      = followers.Count();
                    viewmodel.storeId        = stid;
                    return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) }));
                }
            }
            throw new JsonCustomException(ControllerError.ajaxErrorFollowing);
        }
Ejemplo n.º 22
0
        public ActionResult Create([Deserialize] postVars model, string PrC, string PrS, string post, string filesToUpload)
        {
            //var up = EncryptionHelper.Unprotect(UP);
            //var cp = EncryptionHelper.Unprotect(CP);
            //var sp = EncryptionHelper.Unprotect(SP);
            var prc = EncryptionHelper.Unprotect(PrC);
            var prs = EncryptionHelper.Unprotect(PrS);

            //int?[] receivers = { UP, CP, SP };
            //int?[] senders = { PrC, PrS };

            int?[] senders = { prc, prs };

            if (ModelState.IsValid && senders.Count(x => x != null) <= 1)
            {
                Post   postEntry  = new Post();
                int    senderUser = WebSecurity.CurrentUserId;
                int?   sndr       = null;
                int    recvr      = 0;
                string notifData  = null;

                postEntry.insertDate   = DateTime.UtcNow;
                postEntry.posterUserID = senderUser;
                postEntry.post         = post;

                var notiftype = NotificationType.Post;

                //send to userProfile
                if (model.UId != null)
                {
                    var receiverUser = unitOfWOrk.ActiveUserRepository.GetByID(model.UId);
                    if (receiverUser.Friends.Any(a => a.friendID == senderUser) ||
                        receiverUser.FriendsImIn.Any(a => a.userID == senderUser) ||
                        receiverUser.UserId == senderUser)
                    {
                        postEntry.postedUserID = model.UId;
                        recvr = (int)model.UId;
                    }
                    else
                    {
                        throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                    }
                }
                else if (model.CoId != null)
                {
                    if (unitOfWOrk.NotExpiredCompanyRepository.GetByID(model.CoId).Followers.Any(a => a.followerUserID == senderUser))
                    {
                        postEntry.postedCoID = model.CoId;
                        notiftype            = NotificationType.PostCo;
                        recvr = (int)model.CoId;
                    }
                    else
                    {
                        throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                    }
                }
                else if (model.StId != null)
                {
                    if (unitOfWOrk.StoreNotExpiredRepository.GetByID(model.StId).Followers.Any(a => a.followerUserID == senderUser))
                    {
                        postEntry.postedStoreID = model.StId;
                        notiftype = NotificationType.PostSt;
                        recvr     = (int)model.StId;
                    }
                    else
                    {
                        throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                    }
                }
                else
                {
                    throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                }

                //send as company
                if (prc != null)
                {
                    if (unitOfWOrk.NotExpiredCompanyRepository.GetByID(prc).Admins.Any(a => a.UserId == senderUser))
                    {
                        postEntry.posterCoID = prc;
                        sndr      = prc;
                        notifData = JsonConvert.SerializeObject(new PosterCoNotif {
                            coid = prc
                        });
                    }
                    else
                    {
                        throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                    }
                }
                //send as Store
                else if (prs != null)
                {
                    if (unitOfWOrk.StoreNotExpiredRepository.GetByID(prs).Admins.Any(a => a.UserId == senderUser))
                    {
                        postEntry.posterStoreID = prs;
                        sndr      = prs;
                        notifData = JsonConvert.SerializeObject(new PosterCoNotif {
                            stid = prs
                        });
                    }
                    else
                    {
                        throw new JsonCustomException(Resource.ControllerError.ajaxErrorPostInsert);
                    }
                }


                unitOfWOrk.PostRepository.Insert(postEntry);
                unitOfWOrk.Save();

                NotificationHelper.NotificationInsert(notiftype,
                                                      elemId: postEntry.postID,
                                                      recId: recvr,
                                                      senderCoStoreId: sndr,
                                                      data: notifData
                                                      );
                FeedHelper.FeedInsert(FeedType.Post,
                                      postEntry.postID,
                                      WebSecurity.CurrentUserId);

                if (!String.IsNullOrWhiteSpace(filesToUpload))
                {
                    var fileUploadResult = UploadHelper.UpdateUploadedFiles(filesToUpload, String.Empty, "Post");
                    postEntry.image    = fileUploadResult.ImagesToUpload;
                    postEntry.document = fileUploadResult.DocsToUpload;
                    unitOfWOrk.PostRepository.Update(postEntry);
                }
                unitOfWOrk.Save();
                UnitOfWork newpost = new UnitOfWork();
                var        npost   = newpost.PostRepository.GetByID(postEntry.postID);
                return(Json(new { Success = true, Result = RenderPartialViewHelper.RenderPartialView(this, "PostPartial", npost) }));
            }
            return(Json(new { Success = false, Message = ControllerError.ajaxErrorPostInsert }));
        }
Ejemplo n.º 23
0
        public ActionResult AttendInsert(string ETA, string CA, string SA)
        {
            NullChecker.NullCheck(new object[] { ETA });
            var evtoattend = EncryptionHelper.Unprotect(ETA);

            var eventToAttend = unitOfWork.EventRepository.GetByID(evtoattend);
            var currentUser   = WebSecurity.CurrentUserId;

            if (!String.IsNullOrEmpty(CA) && String.IsNullOrEmpty(SA))
            {
                var companyattend = EncryptionHelper.Unprotect(CA);
                var companyToAdd  = unitOfWork.CompanyRepository.GetByID(companyattend);
                if (companyToAdd.Admins.Any(u => AuthorizationHelper.isRelevant(u.UserId)))
                {
                    if (eventToAttend.AttendorCompanies.Any(u => u.coID == companyattend))
                    {
                        eventToAttend.AttendorCompanies.Remove(companyToAdd);
                        unitOfWork.Save();
                    }
                    else
                    {
                        eventToAttend.AttendorCompanies.Add(companyToAdd);
                        unitOfWork.Save();
                    }
                }
            }
            else if (!String.IsNullOrEmpty(SA) && String.IsNullOrEmpty(CA))
            {
                var storeattend = EncryptionHelper.Unprotect(SA);
                var storeToAdd  = unitOfWork.StoreRepository.GetByID(storeattend);
                if (storeToAdd.Admins.Any(u => AuthorizationHelper.isRelevant(u.UserId)))
                {
                    if (eventToAttend.AttendorStores.Any(u => u.storeID == storeattend))
                    {
                        eventToAttend.AttendorStores.Remove(storeToAdd);
                        unitOfWork.Save();
                    }
                    else
                    {
                        eventToAttend.AttendorStores.Add(storeToAdd);
                        unitOfWork.Save();
                    }
                }
            }
            else if (String.IsNullOrEmpty(SA) && String.IsNullOrEmpty(CA))
            {
                var userToAdd = unitOfWork.ActiveUserRepository.GetByID(currentUser);
                if (eventToAttend.Attendors.Any(u => AuthorizationHelper.isRelevant(u.UserId)))
                {
                    eventToAttend.Attendors.Remove(userToAdd);
                    unitOfWork.Save();
                }
                else
                {
                    eventToAttend.Attendors.Add(userToAdd);
                    unitOfWork.Save();
                }
            }
            UnitOfWork newContext = new UnitOfWork();
            var        newAttend  = newContext.EventRepository.GetByID(evtoattend);

            return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Attend", newAttend) }));
        }