Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public ActionResult AnswerAccept(string AId)
        {
            NullChecker.NullCheck(new object[] { AId });
            var answer = unitOfWork.AnswerRepository.GetByID(EncryptionHelper.Unprotect(AId));

            if (AuthorizationHelper.isRelevant(answer.Question.questionerID))
            {
                if (answer.accept)
                {
                    answer.accept = false;
                    unitOfWork.AnswerRepository.Update(answer);
                    unitOfWork.Save();
                    return(Json(new { Success = true, Result = false }));
                }
                else
                {
                    answer.accept = true;
                    unitOfWork.Save();
                    unitOfWork.AnswerRepository.Update(answer);
                    NotificationHelper.NotificationInsert(NotificationType.AnswerAccept,
                                                          elemId: answer.answerID);
                    FeedHelper.FeedInsert(FeedType.AnswerAccept,
                                          answer.questionID,
                                          answer.answererID
                                          );
                    ScoreHelper.Update(new ScoreVars {
                        type   = ScoreType.Aacc,
                        elemId = answer.answerID,
                        sign   = 1
                    });
                    return(Json(new { Success = true, Result = true }));
                }
            }
            throw new JsonCustomException(ControllerError.ajaxErrorAnswerAcception);
        }
Ejemplo n.º 3
0
        public ActionResult Share(ShareViewModel newShareToInsert, string PId)
        {
            NullChecker.NullCheck(new object[] { PId });
            int user        = WebSecurity.CurrentUserId;
            int pid         = (int)EncryptionHelper.Unprotect(PId);
            var postToshare = unitOfWork.PostRepository.GetByID(pid);

            if (postToshare.Shares.Any(ts => ts.SharerUserID == user))
            {
                throw new JsonCustomException(ControllerError.ajaxErrorPatentUser);
            }
            if (ModelState.IsValid)
            {
                Share finalshareToInsrt = newShareToInsert.Share;
                finalshareToInsrt.SharerUserID = user;
                finalshareToInsrt.sharedPostID = postToshare.postID;
                finalshareToInsrt.shareNote    = newShareToInsert.Share.shareNote;
                finalshareToInsrt.insertdate   = DateTime.UtcNow;
                unitOfWork.ShareRepository.Insert(finalshareToInsrt);
                unitOfWork.Save();
                FeedHelper.FeedInsert(FeedType.SessionOfferLike, postToshare.postID, WebSecurity.CurrentUserId);
                return(Json(new { Success = true, Message = Resource.Resource.sharedSuccessfully }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "title,abtrct,print,translator,writer")] Book book, string professionTags, string UserTags, string filesToUpload)
        {
            if (ModelState.IsValid)
            {
                book.date = DateTime.UtcNow;
                unitOfWork.BookRepository.Insert(book);
                UpdSertBookProffs(professionTags, book);
                UpSertBookUsers(UserTags, book);

                var filesString = filesToUpload.Split(',');
                switch (filesString.Count())
                {
                case 0:
                    throw new JsonCustomException(ControllerError.bookMustUpload);

                case 1:
                    if (!UploadHelper.CheckExtenstionFast(filesString.First(), UploadHelper.FileTypes.doc))
                    {
                        throw new JsonCustomException(ControllerError.bookMustUploadOneDoc);
                    }
                    break;

                case 2:
                    if (!(filesString.Any(i => UploadHelper.CheckExtenstionFast(i, UploadHelper.FileTypes.doc)) &&
                          filesString.Any(i => UploadHelper.CheckExtenstionFast(i, UploadHelper.FileTypes.image))))
                    {
                        throw new JsonCustomException(ControllerError.bookMustUploadOneDocAndImage);
                    }
                    break;

                default:
                    throw new JsonCustomException(ControllerError.fileCountExceeded);
                }

                var fileUploadResult = UploadHelper.UpdateUploadedFiles(filesToUpload, null, "Book");
                book.image = fileUploadResult.ImagesToUpload;
                book.file  = fileUploadResult.DocsToUpload;

                unitOfWork.BookRepository.Update(book);
                unitOfWork.Save();

                foreach (var user in book.Users)
                {
                    FeedHelper.FeedInsert(FeedType.Book,
                                          book.BookId,
                                          user.UserId);
                }
                return(Json(new { URL = Url.Action("Detail", "Book", new { BId = book.BookId, BName = StringHelper.URLName(book.title) }) }));
            }
            throw new ModelStateException(this.ModelState);
        }
        public ActionResult AcceptOffer(string GSOId)
        {
            NullChecker.NullCheck(new object[] { GSOId });

            var offer = unitOfWork.GroupSessionOfferRepository.GetByID(EncryptionHelper.Unprotect(GSOId));

            if (offer.GroupSession.Group.Admins.Any(a => AuthorizationHelper.isRelevant(a.UserId)))
            {
                string text    = Resource.Resource.acceptedNotSessionOffer;
                string message = Resource.Resource.acceptedNotSessionOfferMessage;
                if (offer.isAccepted)
                {
                    offer.isAccepted = false;
                }
                else
                {
                    offer.isAccepted = true;
                    text             = Resource.Resource.acceptedSessionOffer;
                    message          = Resource.Resource.acceptedSessionOfferMessage;
                }
                unitOfWork.GroupSessionOfferRepository.Update(offer);
                unitOfWork.Save();
                if (offer.isAccepted)
                {
                    FeedHelper.FeedInsert(FeedType.SessionOfferAccept,
                                          offer.sessionId,
                                          offer.offererId
                                          );
                    NotificationHelper.NotificationInsert(
                        NotificationType.SessionOfferAccept,
                        elemId: offer.offerId
                        );
                    ScoreHelper.Update(new ScoreVars
                    {
                        type   = ScoreType.GSOacc,
                        elemId = offer.offerId,
                        sign   = 1
                    });
                }

                return(Json(new { Accepted = offer.isAccepted, Message = message, Result = text }));
            }
            throw new JsonCustomException(ControllerError.ajaxError);
        }
Ejemplo n.º 6
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.º 7
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.º 8
0
        public ActionResult Create([Bind(Include = "questionBody,questionSubject,language")] Question question, string professionTags, string filesToUpload)
        {
            if (ModelState.IsValid)
            {
                question.questionerID = WebSecurity.CurrentUserId;
                question.questionDate = DateTime.UtcNow;
                unitOfWork.QuestionRepository.Insert(question);

                UpdSertQuestionProffs(professionTags, question);
                unitOfWork.Save();

                var fileUploadResult = UploadHelper.UpdateUploadedFiles(filesToUpload, null, "Question");
                question.image     = fileUploadResult.ImagesToUpload;
                question.docuoment = fileUploadResult.DocsToUpload;

                unitOfWork.QuestionRepository.Update(question);
                unitOfWork.Save();
                FeedHelper.FeedInsert(FeedType.Question,
                                      question.questionID,
                                      question.questionerID);
                return(Json(new { URL = Url.Action("Detail", "Question", new { QId = question.questionID, QName = StringHelper.URLName(question.questionSubject) }) }));
            }
            throw new ModelStateException(this.ModelState);
        }
Ejemplo n.º 9
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.º 10
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) }));
        }