Example #1
0
        internal int SaveTutorProfile(TutorProfileModel objReq, List<string> fileNamesList)
        {

            using (var db = new WizzDataContext())
            {
                try
                {
                    long userId = Convert.ToInt64(objReq.userId);
                    #region Multiple List work
                    List<tblTutorDoc> objTutorDocList = new List<tblTutorDoc>();
                    objTutorDocList = db.tblTutorDocs.Where(x => x.fkTutorId == userId).ToList();
                    if (objTutorDocList.Count > 0)
                    {
                        db.tblTutorDocs.DeleteAllOnSubmit(objTutorDocList);
                        db.SubmitChanges();
                        objTutorDocList = new List<tblTutorDoc>();
                    }
                    foreach (string n in fileNamesList)
                    {
                        tblTutorDoc objDoc = new tblTutorDoc();
                        objDoc.createdDate = DateTime.UtcNow;
                        objDoc.fileName = n;
                        objDoc.fkTutorId = userId;
                        objDoc.isDelete = false;
                        objTutorDocList.Add(objDoc);
                    }
                    db.tblTutorDocs.InsertAllOnSubmit(objTutorDocList);

                    List<tblTutorSubject> objTutorSubList = new List<tblTutorSubject>();
                    objTutorSubList = db.tblTutorSubjects.Where(x => x.fkTutorId == userId).ToList();
                    if (objTutorSubList.Count > 0)
                    {
                        db.tblTutorSubjects.DeleteAllOnSubmit(objTutorSubList);
                        db.SubmitChanges();
                        objTutorSubList = new List<tblTutorSubject>();
                    }

                    if (objReq.subjectIdList.Count > 0)
                        foreach (string n in objReq.subjectIdList)
                        {
                            tblTutorSubject objTutorSubject = new tblTutorSubject();
                            objTutorSubject.isApproved = false;
                            objTutorSubject.fkSubjectId = Convert.ToInt32(n);
                            objTutorSubject.fkTutorId = userId;
                            objTutorSubject.subjectType = 3;
                            objTutorSubList.Add(objTutorSubject);
                        }
                    else if (objReq.classIdList.Count > 0)
                        foreach (string n in objReq.classIdList)
                        {
                            tblTutorSubject objTutorSubject = new tblTutorSubject();
                            objTutorSubject.isApproved = false;
                            objTutorSubject.fkSubjectId = Convert.ToInt32(n);
                            objTutorSubject.fkTutorId = userId;
                            objTutorSubject.subjectType = 2;
                            objTutorSubList.Add(objTutorSubject);
                        }
                    else
                    {

                        foreach (string n in objReq.courseIdList)
                        {
                            tblTutorSubject objTutorSubject = new tblTutorSubject();
                            objTutorSubject.isApproved = false;
                            objTutorSubject.fkSubjectId = Convert.ToInt32(n);
                            objTutorSubject.fkTutorId = userId;
                            objTutorSubject.subjectType = 1;
                            objTutorSubList.Add(objTutorSubject);
                        }
                    }
                    db.tblTutorSubjects.InsertAllOnSubmit(objTutorSubList);
                    #endregion

                    #region tableTutorprofileEntry
                    tblTutorProfile objTutorProfile = new tblTutorProfile();
                    var previousProfileObj = db.tblTutorProfiles.Where(x => x.fkUserId == userId).FirstOrDefault();
                    if (previousProfileObj != null)
                        db.tblTutorProfiles.DeleteOnSubmit(previousProfileObj);
                    objTutorProfile.feesPerHour = objReq.feesPerHour;
                    objTutorProfile.fkCollegeId = objReq.collegeId == null ? 0 : Convert.ToInt32(objReq.collegeId);
                    objTutorProfile.referralCode = objReq.referralCode == null ? "" : objReq.referralCode;
                    objTutorProfile.isApproved = false;

                    //fake data entry for maintaining previous tblschema (not use ful)
                    objTutorProfile.createdDate = DateTime.UtcNow;
                    objTutorProfile.description = "";
                    objTutorProfile.passingYear = "";

                    //creating a unique search code for tutor
                    objTutorProfile.tutorSearchCode = "W" + objReq.userName.Substring(0, 3) + System.Guid.NewGuid().ToString().Substring(0, 4);


                    //getting radius for tutor
                    objTutorProfile.distance = objReq.distanceRadius;
                    objTutorProfile.fkUserId = userId;
                    objTutorProfile.isActive = true;
                    objTutorProfile.updatedDate = DateTime.UtcNow;
                    objTutorProfile.TimeStamp = DateTime.UtcNow.Ticks;
                    objTutorProfile.lat = Convert.ToDouble(objReq.latitude);
                    objTutorProfile.longi = Convert.ToDouble(objReq.longitude);
                    objTutorProfile.location = objReq.location;
                    db.tblTutorProfiles.InsertOnSubmit(objTutorProfile);
                    #endregion
                    db.SubmitChanges();
                    return 1;
                }
                catch (Exception e)
                {

                    return 0;
                }

            }



        }
        public Response<string> SaveTutorProfile()
        {
            TutorProfileModel objReq = new TutorProfileModel();
            Response<string> response = new Response<string>();
            List<string> objResp = new List<string>();
            int resp = 0;
            try
            {
                objDbMethodV2 = new wizz.Dal.DbMethodsV2();
                if (CheckRequestIsvalidornot(this.Request))
                {
                    HttpContextWrapper objwrapper = GetHttpContext(this.Request);
                    HttpFileCollectionBase collection = objwrapper.Request.Files;
                    string jsonvalue = objwrapper.Request.Form["json"];
                    if (!string.IsNullOrEmpty(jsonvalue))
                    {
                        objReq = JsonConvert.DeserializeObject<TutorProfileModel>(jsonvalue);

                        List<string> newFileNames = new List<string>();

                        newFileNames = SaveMultipleFiles(collection, "");
                        //    objReq.fileNameList = newFileNames;
                        if (newFileNames.Count == 0)
                            response.Create(false, "No Transcripts is uploaded please try again !", Messages.AppVersion, objResp);
                        else
                            resp = objDbMethodV2.SaveTutorProfile(objReq, newFileNames);
                        if (resp == 1)
                        {
                            response.Create(true, "Tutor profile info saved successfully !", Messages.AppVersion, objResp);

                        }
                        else
                        {
                            response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);

                        }

                    }

                }
                return response;
            }
            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;
        }