Esempio n. 1
0
        public async Task <ActionResult> Index()
        {
            var client = MedicoHttpClient.GetClient();

            var model = new MenuViewModel();

            HttpResponseMessage egsResponse = await client.GetAsync("api/menuvoices");

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                var lstMenuVoices = JsonConvert.DeserializeObject <IEnumerable <Model.MenuVoice> >(content);

                model.MenuVoices = lstMenuVoices;
                model.Avatar     = null;
                model.Health     = 100;
                model.Reputation = 100;
                model.UserName   = "******";
            }
            else
            {
                return(Content("An error occurred."));
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
            //return PartialView(model);
        }
Esempio n. 2
0
        public async Task <ActionResult> Contact()
        {
            ViewBag.Message = "Calling web api";


            var client = MedicoHttpClient.GetClient();

            var model = new QuestionViewModel();

            HttpResponseMessage egsResponse = await client.GetAsync("api/questions");

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> MyAnswers(int?page, string userId)
        {
            var client = MedicoHttpClient.GetClient();

            var model   = new MyAnswerViewModel();
            var api_url = "api/myanswers?page=" + page + "&userId=" + userId;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstAnswers = JsonConvert.DeserializeObject <IEnumerable <Model.Answer> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Answer>(lstAnswers, pagingInfo.CurrentPage,
                                                                           pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.MyAnswers  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }
            ViewBag.userId = userId;
            return(View(model));
        }
Esempio n. 4
0
        public async Task <ActionResult> IndexWithSearch(string textLike, int?page)
        {
            var client = MedicoHttpClient.GetClient();
            //var client = new HttpClient();
            //client.BaseAddress = new System.Uri("http://localhost:2627/");


            var model = new QuestionViewModel();

            string _textlike = textLike == null ? "" : textLike;
            var    api_url   = "";

            if (page == null)
            {
                api_url = "api/questionslike?textlike=" + _textlike;
            }
            else
            {
                api_url = "api/questionslike?textlike=" + _textlike + "&page=" + page;
            }

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            ViewBag.TextLike = textLike;
            return(View(model));
        }
Esempio n. 5
0
        public async Task <ActionResult> All()
        {
            var client = MedicoHttpClient.GetClient();

            var    model   = new TagViewModel();
            String api_url = "api/tagslist";

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                var lstTags = JsonConvert.DeserializeObject <IEnumerable <Model.Tag> >(content);
                model.Tags = lstTags;
            }
            else
            {
                return(Content(egsResponse.StatusCode.ToString()));
            }
            return(View(model));
        }
Esempio n. 6
0
        public async Task <ActionResult> GetMyProfile()
        {
            var client = MedicoHttpClient.GetClient();

            string userIdentityName = User.Identity.Name;
            string api_url          = "api/userbyemail?email=" + userIdentityName;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                var    user        = JsonConvert.DeserializeObject <Model.User>(content);
                string redirectUrl = "/User/MyProfile/" + user.ProfileUser.Id;

                return(Redirect(redirectUrl));
            }
            else
            {
                return(Redirect("/Error/Error_500"));
            }
        }
Esempio n. 7
0
        public async Task <ActionResult> GetQuestionsByTag(int page, int tagId, string tagName)
        {
            var client = MedicoHttpClient.GetClient();

            var model = new QuestionViewModel();

            var api_url = "api/questionsbytag?page=" + page + "&tagId=" + tagId;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                // get the paging info from the header
                var pagingInfo = HeaderParser.FindAndParsePagingInfo(egsResponse.Headers);

                var lstQuestions = JsonConvert.DeserializeObject <IEnumerable <Model.Question> >(content);

                var pagedQuestionList = new StaticPagedList <Model.Question>(lstQuestions, pagingInfo.CurrentPage,
                                                                             pagingInfo.PageSize, pagingInfo.TotalCount);

                //var pagedQuestionList = lstQuestions.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize);

                model.Questions  = pagedQuestionList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error occurred."));
            }

            ViewBag.tagId   = tagId;
            ViewBag.tagName = tagName;
            return(View(model));
        }
Esempio n. 8
0
        public async Task <ActionResult> MyProfile(int id)
        {
            var client = MedicoHttpClient.GetClient();

            var model = new ProfileViewModel();

            String api_url = "api/profile/" + id;

            HttpResponseMessage egsResponse = await client.GetAsync(api_url);

            if (egsResponse.IsSuccessStatusCode)
            {
                string content = await egsResponse.Content.ReadAsStringAsync();

                var profile = JsonConvert.DeserializeObject <Model.Profile>(content);

                string lastLoginDate = profile.User.LastLoginDate.HasValue ? profile.User.LastLoginDate.Value.ToShortDateString() : DateTime.Now.ToShortDateString();
                string dateOfBirth   = profile.DateOfBirth.HasValue ? profile.DateOfBirth.Value.ToShortDateString() : "Non Dichiarato";
                string gender        = "";
                switch (profile.Gender)
                {
                case Constants.EnumGender.Male:
                    gender = "M";
                    break;

                case Constants.EnumGender.Female:
                    gender = "F";
                    break;

                case Constants.EnumGender.NonDefinito:
                    gender = "?";
                    break;

                default:
                    break;
                }
                string role = "";
                switch (profile.User.Role)
                {
                case Constants.EnumUserRole.SuperAdmin:
                    role = "SuperAdmin";
                    break;

                case Constants.EnumUserRole.Admin:
                    role = "Admin";
                    break;

                case Constants.EnumUserRole.User:
                    role = "User";
                    break;

                default:
                    break;
                }
                string status = "";
                switch (profile.User.Status)
                {
                case Constants.EnumUserStatus.Actived:
                    status = "Attivato";
                    break;

                case Constants.EnumUserStatus.Disabled:
                    status = "Disabilitato";
                    break;

                case Constants.EnumUserStatus.WaitingActivaction:
                    status = "In attesa di Attivazione";
                    break;

                default:
                    break;
                }

                ProfileViewModel vm = new ProfileViewModel()
                {
                    Id            = profile.Id,
                    FirstName     = profile.FirstName,
                    LastName      = profile.LastName,
                    Title         = profile.Title,
                    Photo         = profile.Photo,
                    Address1      = profile.Address1,
                    Address2      = profile.Address1,
                    City          = profile.City,
                    Country       = profile.Country,
                    Mobile        = profile.Mobile,
                    DateOfBirth   = dateOfBirth,
                    Gender        = gender,
                    CreateDate    = profile.User.CreateDate.ToShortDateString(),
                    Email         = profile.User.Email,
                    LastLoginDate = lastLoginDate,
                    NickName      = profile.User.NickName,
                    Role          = role,
                    Status        = status
                };
                model = vm;
            }
            else
            {
                return(Content("An error occurred."));
            }
            return(View(model));
        }