예제 #1
0
        public async Task<JsonResult> Invoice(Offer question)
        {
            var user = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.TutorID.Value == new Guid(user)).First();
            if (session.Status == Status.Hired || session.Status==Status.Invoiced)
            {
                session.OfferedFees = question.amount;
                session.Status = Status.Invoiced;
                db.Entry(session).State = EntityState.Modified;

                DBEntities.Transaction tran = new DBEntities.Transaction();
                tran.TransactionID = Guid.NewGuid();
                tran.SessionID = sessionId;
                tran.Status = Status.Invoiced;
                tran.OfferedFees = question.amount;
                tran.PostedTime = DateTime.Now;
                db.transcations.Add(tran);

                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have sent Invoice for the work for $" + question.amount + ". Press Accept Button if you are satisfied with the services and pay to tutor. Pressing Reject button will cause the admin to decide the dispute.";
                session.Replies.Add(obj);

                db.SaveChanges();

                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                //send message reply
                var username = User.Identity.Name;
                var imgsrc = db.Tutors.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString(),false);
                SendChatTutorReciever(obj.SessionID.ToString(), username, message, context); //send message to urself 

                var student = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().question.student;
                var username2 = student.Username;
                SendChatStudentReiever(obj.SessionID.ToString(), username2, message, context); //send message to other person 

                //send button
                
                var message2 = "<button type =\"button\" id=\"accept\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#approveNewModal\" style=\"margin-right:5px\">Accept </button>";
                message2 = message2 + "<button type =\"button\" id=\"reject\" class=\"btn  btn-primary\" data-toggle=\"modal\" data-target=\"#rejectNewModal\">Reject </button>";

                   SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 
                   SendNotification(username2, username, imgsrc, "I have sent Invoice of $" + question.amount,true, "Students", "Sessions", "SessionId=" + sessionId);
                
                //send email
                var email = db.Users.Where(c => c.Id == session.question.StudentID.ToString()).FirstOrDefault().Email;
                String subject = "Tutor sent Invoice on MezoExperts.com";
                String bodyText = username + " has sent invoice for $" + question.amount;
                string fileTemplate = "passwordreset.html";
                await sendEmail(email, subject, bodyText, fileTemplate, "");

                
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = question.amount }
                };
            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "" }
                };
            }

        }
        public async Task<JsonResult> ApprovePayment(Offer question)
        {
            var user = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.question.StudentID == new Guid(user)).First();
            if (session.Status == Status.Invoiced)
            {
                session.Status = Status.Approved;
                session.isClosed = true;
                var quest = session.question;
                quest.Status = Status.Approved;
                db.Entry(quest).State = EntityState.Modified;
                db.Entry(session).State = EntityState.Modified;
               
                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have Approved the payment for " + session.OfferedFees + "$. ";
                session.Replies.Add(obj);

                db.SaveChanges();


                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                var username = User.Identity.Name;
                var imgsrc = db.Students.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString());
                SendChatMessageStudentReciever(obj.SessionID.ToString(), username, message, context); //send message to urself 
                var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor;
                var username2 = tutor.Username;
                SendChatMessageTutorReciever(obj.SessionID.ToString(), username2, message, context); //send message to other person 

                var message2 = " <button type=\"button\" id=\"accepted\" disabled class=\"btn btn-primary\">Accepted Invoice</button>";

                SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 


                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "success" }
                };

            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "fail" }
                };

            }
        }
        public async Task<JsonResult> Hire(Offer question)
        {
            var userId = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.question.StudentID == new Guid(userId)).First();
            var user = session.question.student;
            if(user.CurrentBalance < session.OfferedFees)
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "You donot have enough funds to hire the expert.Go to Account Settings and add funds first." }
                };
            }
            else if(session.Status == Status.Offered)
            {
                session.Status = Status.Hired;
                var quest = session.question;
                quest.Status = Status.Hired;
                db.Entry(quest).State = EntityState.Modified;
                db.Entry(session).State = EntityState.Modified;

                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have Hired you for " + session.OfferedFees + "$. You can start working on task." ;
                session.Replies.Add(obj);

                

                db.SaveChanges();

           
                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                var username = User.Identity.Name;
                var imgsrc = db.Students.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString());
                SendChatMessageStudentReciever(obj.SessionID.ToString(), username, message, context); //send message to urself 
                var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor;
                var username2 = tutor.Username;
                SendChatMessageTutorReciever(obj.SessionID.ToString(), username2, message, context); //send message to other person 

                //send button
               
                var message2 = "  <button type=\"button\" id=\"hire\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#invoiceNewModal\">Send Invoice</button>";
                                                                                       
                SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 


                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "success" }
                };

            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "fail" }
                };

            }
        }
        public async Task<JsonResult> Rate(Offer question)
        {
            var user = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.question.StudentID == new Guid(user)).First();
            if (session.Status == Status.Approved)
            {
                session.ratings = Convert.ToDouble(question.Rating);
                db.Entry(session).State = EntityState.Modified;

                var tutorSession = db.sessions.Where(c => c.TutorID == session.TutorID && c.Status==Status.Approved).ToList();
                int count = 0;
                float sum = 0;
                foreach (var t  in tutorSession)
                {
                    if (t.ratings != null) { 
                        sum = sum +(float) t.ratings.Value;
                        count++;
                    }
                }

                float rating = 0;

                if(count>0)
                    rating=sum / count;

                var tutor = db.Tutors.Where(c => c.TutorID == session.TutorID.Value).FirstOrDefault();
                tutor.Rating = rating;
                db.Entry(tutor).State = EntityState.Modified;
                db.SaveChanges();
                

                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "success" }
                };

            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "fail" }
                };

            }
        }
예제 #5
0
 public ChatModel()
 {
     offer = new Offer();
 }
예제 #6
0
        public async Task<JsonResult> SendOffer( Offer question)
        {
            var user = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID ==sessionId && c.TutorID.Value ==new Guid(user)).First();
            if(session.Status==Status.Posted || session.Status == Status.Offered)
            { 
                session.OfferedFees = question.amount;
                session.Status = Status.Offered;
                db.Entry(session).State = EntityState.Modified;

                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have sent offer to do your work for " + question.amount + "$. Press Hire Button if you are interested in my services.";
                session.Replies.Add(obj);
                db.SaveChanges();

                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                //send message reply
                var username = User.Identity.Name;
                var imgsrc = db.Tutors.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString());
                SendChatTutorReciever(obj.SessionID.ToString(), username, message, context); //send message to urself 

                var student = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().question.student;
                var username2 = student.Username;
                SendChatStudentReiever(obj.SessionID.ToString(), username2, message, context); //send message to other person 
               
                //send button update
                var message2 = "<button type=\"button\" id=\"offer\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#hireNewModal\">Hire for ("+question.amount+"$)</button>";
                SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 

                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = question.amount }
                };
            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "" }
                };
            }

        }
        public async Task<JsonResult> Hire(Offer question)
        {
            var userId = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.question.StudentID == new Guid(userId)).First();
            var user = session.question.student;
            if(user.CurrentBalance < session.OfferedFees)
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "You donot have enough funds to hire the expert.Go to Account Settings and add funds first." }
                };
            }
            else if(session.Status == Status.Offered)
            {
                session.Status = Status.Hired;
                var quest = session.question;
                quest.Status = Status.Hired;
                user.CurrentBalance = user.CurrentBalance - (float)session.OfferedFees;
                db.Entry(user).State = EntityState.Modified; 
                db.Entry(quest).State = EntityState.Modified;
                db.Entry(session).State = EntityState.Modified;

                //hire transaction
                DBEntities.Transaction tran = new DBEntities.Transaction();
                tran.TransactionID = Guid.NewGuid();
                tran.SessionID = sessionId;
                tran.Status = Status.Hired;
                tran.OfferedFees = question.amount;
                tran.PostedTime = DateTime.Now;
                db.transcations.Add(tran);

                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have Hired you for $" + session.OfferedFees + ". You can start working on task." ;
                session.Replies.Add(obj);

                

                db.SaveChanges();

           
                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                var username = User.Identity.Name;
                var imgsrc = db.Students.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString(),false);
                SendChatMessageStudentReciever(obj.SessionID.ToString(), username, message, context); //send message to urself 
                var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor;
                var username2 = tutor.Username;
                SendChatMessageTutorReciever(obj.SessionID.ToString(), username2, message, context); //send message to other person 

                //send button
               
                var message2 = "  <button type=\"button\" id=\"hire\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#invoiceNewModal\">Send Invoice</button>";
                                                                                       
                SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 
                SendNotification(username2, username,imgsrc, "I have hired you for $"+session.OfferedFees,true,"Tutors","Sessions", "SessionId="+sessionId);

                var email = db.Users.Where(c => c.Id == quest.TutorID.ToString()).FirstOrDefault().Email;
                String subject = "Hired on MezoExperts.com";
                String bodyText = username + " has hired you for the job.";
                string fileTemplate = "passwordreset.html";
                await sendEmail(email, subject, bodyText,fileTemplate,"");
                
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "success" }
                };

            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "fail" }
                };

            }
        }
        public async Task<JsonResult> ApprovePayment(Offer question)
        {
            var user = User.Identity.GetUserId();
            var sessionId = question.SessionId;
            var session = db.sessions.Where(c => c.SessionID == sessionId && c.question.StudentID == new Guid(user)).First();
            if (session.Status == Status.Invoiced)
            {
                session.Status = Status.Approved;
                session.isClosed = true;
                var quest = session.question;
                quest.Status = Status.Approved;
                db.Entry(quest).State = EntityState.Modified;
                db.Entry(session).State = EntityState.Modified;

                DBEntities.Transaction tran = new DBEntities.Transaction();
                tran.TransactionID = Guid.NewGuid();
                tran.SessionID = sessionId;
                tran.Status = Status.Approved;
                tran.OfferedFees = question.amount;
                tran.PostedTime = DateTime.Now;
                db.transcations.Add(tran);

                Reply obj = new Reply();
                obj.ReplyID = Guid.NewGuid();
                obj.ReplierID = new Guid(User.Identity.GetUserId());
                obj.SessionID = sessionId;
                obj.PostedTime = DateTime.Now;
                obj.Details = " Automatically Generated Message: I have Approved the payment for " + session.OfferedFees + "$. ";
                session.Replies.Add(obj);

                var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor;
                tutor.CurrentEarning = tutor.CurrentEarning + (float)session.OfferedFees;
                db.Entry(tutor).State = EntityState.Modified; 

                db.SaveChanges();


                var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>();
                var username = User.Identity.Name;
                var imgsrc = db.Students.Where(c => c.Username == username).FirstOrDefault().ProfileImage;
                string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(), obj.ReplyID.ToString(),false);
                SendChatMessageStudentReciever(obj.SessionID.ToString(), username, message, context); //send messageFp to urself 
                //var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor;
                var username2 = tutor.Username;
                SendChatMessageTutorReciever(obj.SessionID.ToString(), username2, message, context); //send message to other person 

                var message2 = " <button type=\"button\" id=\"accepted\" disabled class=\"btn btn-primary\">Accepted Invoice</button>";

                SendButtonStudent(sessionId.ToString(), username2, message2, context); //send message to other person 
                SendNotification(username2, session.question.student.Username, session.question.student.ProfileImage, "I have approved the payment of $" + session.OfferedFees,true, "Tutors", "Sessions", "SessionId=" + sessionId);
                //close sessions
                DeleteSessionMessageTutor(sessionId.ToString(), username2, "", context);
                DeleteSessionMessageTutor(sessionId.ToString(), username, "", context);

                var email = db.Users.Where(c => c.Id == quest.TutorID.ToString()).FirstOrDefault().Email;
                String subject = "Invoice Approved on MezoExperts.com";
                String bodyText = username + " approved the Invoice.";
                string FileTemplate = "passwordreset.html";
                await sendEmail(email, subject, bodyText, FileTemplate, "");


                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "success" }
                };

            }
            else
            {
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "fail" }
                };

            }
        }