Example #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Flag")] CountryViewModel country, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var photoUrl = Upload(file);
                country.Flag = photoUrl.Substring(1, photoUrl.Length - 2);

                var client   = GlobalWebApiClient.GetClientRegion();
                var response = client.PostAsJsonAsync("api/countries/save/", country).Result;
                try
                {
                    if (response.IsSuccessStatusCode)
                    {
                        country = response.Content.ReadAsAsync <CountryViewModel>().Result;
                        TempData["SuccessMessage"] = "Country created successfully";
                        return(RedirectToAction("Details", country.Id));
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }
            return(View(country));
        }
Example #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            if (ModelState.IsValid)
            {
                var client   = GlobalWebApiClient.GetClientRegion();
                var response = client.DeleteAsync("api/countries/country/del/" + id.ToString()).Result;

                try
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var country = response.Content.ReadAsAsync <CountryViewModel>().Result;
                        TempData["SuccessMessage"] = "Country deleted successfully";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }
            return(View());
        }
 public ActionResult Create([Bind(Include = "Id,Street,Number,Neighborhood,City,PostalCode")] AddressViewModel address)
 {
     if (ModelState.IsValid)
     {
         var client   = GlobalWebApiClient.GetClientRegion();
         var response = client.PostAsJsonAsync("api/addresses/save/", address).Result;
         try
         {
             if (response.IsSuccessStatusCode)
             {
                 address = response.Content.ReadAsAsync <AddressViewModel>().Result;
                 TempData["SuccessMessage"] = "Address created successfully";
                 return(RedirectToAction("Details", address));
             }
         }
         catch (Exception ex)
         {
             var result = ex.Message;
         }
     }
     else
     {
         ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
     }
     return(View(address));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,Flag")] CountryViewModel country)
 {
     if (ModelState.IsValid)
     {
         var client   = GlobalWebApiClient.GetClientRegion();
         var response = client.PutAsJsonAsync("/api/countries/update/", country).Result;
         try
         {
             if (response.IsSuccessStatusCode)
             {
                 country = response.Content.ReadAsAsync <CountryViewModel>().Result;
                 TempData["SuccessMessage"] = "Country updated successfully";
                 return(RedirectToAction("Details", country));
             }
         }
         catch (Exception ex)
         {
             var result = ex.Message;
         }
     }
     else
     {
         ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
     }
     return(View(country));
 }
Example #5
0
        // GET: Countries/Edit/5
        public ActionResult Edit(Guid?id)
        {
            var client   = GlobalWebApiClient.GetClientRegion();
            var response = client.GetAsync("api/countries/country/info/" + id.ToString()).Result;

            if (response.IsSuccessStatusCode)
            {
                var country = response.Content.ReadAsAsync <CountryViewModel>().Result;
                return(View(country));
            }
            else
            {
                return(View());
            }
        }
Example #6
0
        // GET: States/Delete/5
        public ActionResult Delete(Guid?id)
        {
            var client   = GlobalWebApiClient.GetClientRegion();
            var response = client.GetAsync("api/states/state/info/" + id.ToString()).Result;

            if (response.IsSuccessStatusCode)
            {
                var state = response.Content.ReadAsAsync <StateViewModel>().Result;
                return(View(state));
            }
            else
            {
                return(View());
            }
        }
Example #7
0
        //POST: Countries/Upload
        public String Upload(HttpPostedFileBase file)
        {
            if (Session["Token"] != null)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        const String URI_ADDRESS = "api/countries/upload";
                        var          client      = GlobalWebApiClient.GetClientRegion();

                        using (var content = new MultipartFormDataContent())
                        {
                            byte[] Bytes = new byte[file.InputStream.Length + 1];
                            file.InputStream.Read(Bytes, 0, Bytes.Length);
                            var fileContent = new ByteArrayContent(Bytes);
                            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                            {
                                FileName = file.FileName
                            };
                            content.Add(fileContent);

                            var response = client.PostAsync(URI_ADDRESS, content).Result;

                            if (response.IsSuccessStatusCode)
                            {
                                var photoUrl = response.Content.ReadAsStringAsync().Result;
                                return(photoUrl);
                            }
                            else
                            {
                                ViewBag.Failed = "Failed! " + response.Content.ToString();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var result = ex.Message;
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                }
            }

            return(null);
        }
Example #8
0
        // GET: Countries/Details/5
        public ActionResult Details(Guid?id)
        {
            var client   = GlobalWebApiClient.GetClientRegion();
            var response = client.GetAsync("api/countries/country/info/" + id.ToString()).Result;

            if (response.IsSuccessStatusCode)
            {
                var country = response.Content.ReadAsAsync <CountryViewModel>().Result;
                return(View(country));
            }
            else
            {
                ViewBag.Result = "Server Error. Please contact administrator!";
            }
            return(View());
        }
        public ActionResult Edit(Guid countryId, Guid stateId, ProfileViewModel profile, HttpPostedFileBase file)
        {
            if (Session["Email"] != null)
            {
                if (ModelState.IsValid)
                {
                    var photoUrl = Upload(file);

                    try
                    {
                        var clientRegion  = GlobalWebApiClient.GetClientRegion();
                        var CountryResult = clientRegion.GetAsync("api/countries/country/info/" + countryId.ToString()).Result;
                        var StateResult   = clientRegion.GetAsync("api/states/state/info/" + stateId.ToString()).Result;

                        if (CountryResult.IsSuccessStatusCode && StateResult.IsSuccessStatusCode)
                        {
                            var cvm = CountryResult.Content.ReadAsAsync <CountryViewModel>().Result;
                            var svm = StateResult.Content.ReadAsAsync <StateViewModel>().Result;

                            profile.PhotoUrl = photoUrl.Substring(1, photoUrl.Length - 2);
                            profile.Country  = cvm;
                            profile.State    = svm;

                            var client   = GlobalWebApiClient.GetClient();
                            var response = client.PutAsJsonAsync("api/profiles/update/", profile).Result;

                            if (response.IsSuccessStatusCode)
                            {
                                profile = response.Content.ReadAsAsync <ProfileViewModel>().Result;
                                TempData["SuccessMessage"] = "Profile updated successfully";

                                return(RedirectToAction("Details", profile));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var result = ex.Message;
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                }
            }
            return(RedirectToAction("Login", "Account"));
        }
Example #10
0
        // GET: Countries
        public ActionResult Index()
        {
            IEnumerable <CountryViewModel> countries;
            var client   = GlobalWebApiClient.GetClientRegion();
            var response = client.GetAsync("api/countries/all").Result;

            if (response.IsSuccessStatusCode)
            {
                countries = response.Content.ReadAsAsync <IEnumerable <CountryViewModel> >().Result;
                return(View(countries.ToList()));
            }
            else
            {
                ViewBag.Result = "Server Error. Please contact administrator!";
            }
            return(View());
        }
        //GET: Profiles/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if ((Session["Email"] == null) || !(id.ToString().Equals(Session["UserId"].ToString())))
            {
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                try
                {
                    var clientRegion  = GlobalWebApiClient.GetClientRegion();
                    var CountryResult = clientRegion.GetAsync("api/countries/all").Result;
                    var StateResult   = clientRegion.GetAsync("api/states/all").Result;

                    if (CountryResult.IsSuccessStatusCode && StateResult.IsSuccessStatusCode)
                    {
                        var countries = CountryResult.Content.ReadAsAsync <IEnumerable <CountryViewModel> >().Result;
                        var states    = StateResult.Content.ReadAsAsync <IEnumerable <CountryViewModel> >().Result;

                        ViewBag.Countries = countries.ToList();
                        ViewBag.States    = states.ToList();
                    }

                    var client   = GlobalWebApiClient.GetClient();
                    var response = client.GetAsync(@"api/profiles/profile/info/" + id.ToString()).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        var profile = response.Content.ReadAsAsync <ProfileViewModel>().Result;
                        return(View(profile));
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            return(View("Error"));
        }
        //GET: Profiles/Create
        public ActionResult Create()
        {
            var clientUser = GlobalWebApiClient.GetClient();
            var result     = clientUser.GetAsync("api/Account/LoggedUser").Result;

            //var result = clientUser.GetAsync(@"api/profiles/profile/" + Session["Email"].ToString().EncodeBase64()).Result;

            if (result.IsSuccessStatusCode)
            {
                var user = result.Content.ReadAsAsync <ProfileViewModel>();

                var userId = user.Result.Id.ToString();
                if ((Session["Email"] == null) || !(userId.Equals(Session["UserId"].ToString())))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    var client          = GlobalWebApiClient.GetClientRegion();
                    var responseCountry = client.GetAsync("api/countries/all").Result;
                    var responseState   = client.GetAsync("api/states/all").Result;

                    if (responseCountry.IsSuccessStatusCode && responseState.IsSuccessStatusCode)
                    {
                        var countries = responseCountry.Content.ReadAsAsync <IEnumerable <CountryViewModel> >().Result;
                        var states    = responseState.Content.ReadAsAsync <IEnumerable <CountryViewModel> >().Result;

                        ViewBag.Countries = countries.ToList();
                        ViewBag.States    = states.ToList();

                        return(View());
                    }
                    else
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                }
            }
            return(RedirectToAction("Login", "Account"));
        }
        //GET: Profiles/Details/5
        public ActionResult Details(Guid?id)
        {
            ProfileViewModel pvm = null;

            if (id == null)
            {
                if (Session["Email"] == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    try
                    {
                        var client = GlobalWebApiClient.GetClientRegion();

                        var response = client.GetAsync(@"api/profiles/profile/" + Session["Email"].ToString().EncodeBase64()).Result;

                        if (response.IsSuccessStatusCode)
                        {
                            pvm = response.Content.ReadAsAsync <ProfileViewModel>().Result;
                            id  = pvm.Id;
                        }
                        else
                        {
                            ViewBag.Result = "Server Error. Please contact administrator!";
                        }
                    }
                    catch (Exception ex)
                    {
                        var result = ex.Message;
                    }
                }
            }
            else
            {
                try
                {
                    var client1         = GlobalWebApiClient.GetClient();
                    var responseProfile = client1.GetAsync("api/profiles/profile/info/" + id.ToString()).Result;
                    //var fsResult = JsonConvert.DeserializeObject<IEnumerable<FriendShipViewModel>>(client.GetStringAsync(@"api/friendships/all").Result);

                    if (responseProfile.IsSuccessStatusCode)
                    {
                        var profileViewModel = responseProfile.Content.ReadAsAsync <ProfileViewModel>().Result;
                        var userId           = Guid.Parse(Session["UserId"].ToString());

                        if (profileViewModel.Id == userId)
                        {
                            var friends = client1.GetAsync("api/friendships/friends/" + userId.ToString()).Result;

                            ProfileViewModel myFriend   = null;
                            bool             isMyFriend = false;

                            if (friends.IsSuccessStatusCode)
                            {
                                var myFriendShips = friends.Content.ReadAsAsync <IEnumerable <ProfileViewModel> >().Result;

                                if (myFriendShips.Count() > 0)
                                {
                                    myFriend = myFriendShips.FirstOrDefault(p => p.Id.Equals(p.Id));

                                    var friendResult = client1.GetAsync("api/profiles/profile/info/" + myFriend.Id.ToString()).Result;
                                    var pvmFriend    = friendResult.Content.ReadAsAsync <ProfileViewModel>().Result;

                                    isMyFriend = myFriendShips.Any(p => p.Id == pvmFriend.Id);

                                    var friendShip = new FriendShipViewModel();
                                    if (isMyFriend)
                                    {
                                        //ViewBag.IsFriend = isMyFriend;
                                        friendShip.Status = StatusEnumViewModel.Accepted;
                                    }

                                    var friendId = Guid.Parse(myFriend.Id.ToString());
                                    foreach (var myFriendShip in myFriendShips)
                                    {
                                        if (myFriendShip.Id.Equals(friendId) && !friendShip.Status.Equals(StatusEnumViewModel.Accepted))
                                        {
                                            ViewBag.IsFriend = isMyFriend;
                                            return(View(profileViewModel));
                                        }
                                        else if (myFriendShip.Id.Equals(friendId) && friendShip.Status.Equals(StatusEnumViewModel.Accepted))
                                        {
                                            ViewBag.FriendsCount = myFriendShips.ToList().Count;
                                            ViewBag.Friends      = myFriendShips.ToList();
                                            ViewBag.IsFriend     = isMyFriend;
                                            return(View(profileViewModel));
                                        }
                                    }
                                }

                                ViewBag.FriendsCount = myFriendShips.Count();
                                ViewBag.Friends      = myFriendShips.ToList();
                                ViewBag.IsFriend     = isMyFriend;
                                return(View(profileViewModel));
                            }
                        }

                        var client2       = GlobalWebApiClient.GetClient();
                        var friendsResult = client2.GetAsync("api/friendships/friends/" + id.ToString()).Result;

                        if (friendsResult.IsSuccessStatusCode)
                        {
                            var myFriendShips = friendsResult.Content.ReadAsAsync <IEnumerable <ProfileViewModel> >().Result;

                            bool isMyFriend = myFriendShips.Any(p => p.Id == userId);

                            var friendShip = new FriendShipViewModel();

                            if (isMyFriend)
                            {
                                //ViewBag.IsFriend = isMyFriend;
                                friendShip.Status = StatusEnumViewModel.Accepted;

                                foreach (var myFriendShip in myFriendShips)
                                {
                                    if (myFriendShip.Id.Equals(userId) && !friendShip.Status.Equals(StatusEnumViewModel.Accepted))
                                    {
                                        ViewBag.IsFriend = isMyFriend;
                                        return(View(profileViewModel));
                                    }
                                    else if (myFriendShip.Id.Equals(userId) && friendShip.Status.Equals(StatusEnumViewModel.Accepted))
                                    {
                                        ViewBag.FriendsCount = myFriendShips.Count();
                                        ViewBag.Friends      = myFriendShips.ToList();
                                        ViewBag.IsFriend     = isMyFriend;
                                        return(View(profileViewModel));
                                    }
                                }
                            }
                        }
                        return(View(profileViewModel));
                    }
                    else
                    {
                        ViewBag.Result = "Server Error. Please contact administrator!";
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            return(View("Error"));
        }