Exemplo n.º 1
0
        internal bool SessionRatingByStudent(StudentRatingwModel objReq)
        {
            using (var db = new WizzDataContext())
            {
                tblTutorRating rating = new tblTutorRating();
                var sessionData = db.tblSessions.FirstOrDefault(x => x.pkSessionId == Convert.ToInt64(objReq.sessionId));
                rating = db.tblTutorRatings.FirstOrDefault(x => x.sessionId == objReq.sessionId && x.fkStudentId == Convert.ToInt32(objReq.userId));
                var tutorRating = db.tblUsers.Where(x => x.pkUserId == Convert.ToInt64(sessionData.tutorId)).FirstOrDefault();
                if (rating == null)
                {

                    rating = new tblTutorRating();
                    rating.createdDate = DateTime.UtcNow;
                    rating.sessionId = objReq.sessionId;
                    rating.userName = objReq.userName;
                    rating.fkStudentId = Convert.ToInt32(objReq.userId);
                    rating.fkTutorId = sessionData.tutorId;
                    rating.updatedDate = DateTime.UtcNow;
                    rating.punctual = Convert.ToInt16(objReq.punctual);
                    rating.knowledgable = Convert.ToInt16(objReq.knowledge);
                    rating.helpful = Convert.ToInt16(objReq.helpFul);
                    rating.review = "";
                    tutorRating.avgRatingTutor = ((tutorRating.avgRatingTutor) + (rating.punctual + rating.knowledgable + rating.helpful) / 3) / 2;
                    db.tblTutorRatings.InsertOnSubmit(rating);
                }
                else
                {

                    rating.userName = objReq.userName;
                    rating.updatedDate = DateTime.UtcNow;
                    rating.punctual = Convert.ToInt16(objReq.punctual);
                    rating.knowledgable = Convert.ToInt16(objReq.knowledge);
                    rating.helpful = Convert.ToInt16(objReq.helpFul);
                    tutorRating.avgRatingTutor = ((tutorRating.avgRatingTutor) + (rating.punctual + rating.knowledgable + rating.helpful) / 3) / 2;
                    
                }
                db.SubmitChanges();
                return true;


            }
        }
        public Response<string> SessionRatingByStudent(StudentRatingwModel objReq)
        {
            Response<string> response = new Response<string>();
            List<string> objResp = new List<string>();
            try
            {
                Session obj = new Session();
                if (CheckRequestIsvalidornot(this.Request))
                {
                    if (ModelState.IsValid)
                    {
                        if (obj.SessionRatingByStudent(objReq))
                            response.Create(true, Messages.FormatMessage(Messages.Success, "You have rated"), Messages.AppVersion, objResp);
                        else
                            response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);

                    }
                    else
                        response.Create(false, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage, Messages.AppVersion, objResp);
                }
            }
            catch (Exception ex)
            {
                object session = new JavaScriptSerializer().Serialize(objReq);
                LogManager.Error("Error occured while Processing Webservice request :{0}", ex, session, ex.Message);
                response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);
            }
            return response;
        }