public ActionResult Index(UsertableView updatedDetails)
 {
     userdetails             = (UsertableView)Session["userdetailspost"];
     updatedDetails.usertype = new RoletypeDTO()
     {
         //roleid=2,
         roleid        = userdetails.usertype.roleid,
         user_type     = userdetails.usertype.user_type,
         UsertableDTOs = null
     };
     if (ModelState.IsValid && Session["userid"] != null)
     {
         string editProfileGetUrl = "api/Users";
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri(baseurl);
             var response = client.PutAsJsonAsync <UsertableView>(editProfileGetUrl, updatedDetails);
             response.Wait();
             var result = response.Result;
             if (result.IsSuccessStatusCode)
             {
                 ViewBag.EditProfileMessage = "Profile Edited Successfully and please login again with updated credentials";
             }
             else
             {
                 ViewBag.EditProfileMessageFailed = "Failed to update details. Please try again";
             }
         }
     }
     return(View(updatedDetails));
 }
        public ActionResult Index()
        {
            if (Session["userid"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            if (Session["userid"] != null)
            {
                int    userid            = int.Parse(Session["userid"].ToString());
                string editProfileGetUrl = "api/Users?userid=" + userid;
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseurl);
                    var response = client.GetAsync(editProfileGetUrl);
                    response.Wait();
                    var result = response.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <UsertableView>();
                        readTask.Wait();
                        userdetails = readTask.Result;

                        if (userdetails != null)
                        {
                            //UsertableDTO userDetails =
                            Session["userdetailspost"] = userdetails;
                            return(View(userdetails));
                        }
                    }
                }
            }
            return(View("Index", "Login"));
        }
Exemple #3
0
        public ActionResult Index(UsertableDTO usertable)
        {
            bool isSignupSuccessful = false;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseurl);
                UsertableView usertableview = new UsertableView();
                usertableview.userid         = usertable.userid;
                usertableview.name           = usertable.name;
                usertableview.password       = usertable.password;
                usertableview.email          = usertable.email;
                usertableview.contact_number = usertable.contact_number;
                usertableview.username       = usertable.username;
                //create constant to check usertype - use enum

                //if (usertable.usertype.ToString() == "seller")
                if (usertable.usertype.ToString() == usertypeenum.seller.ToString())
                {
                    usertableview.usertype = new RoletypeDTO()
                    {
                        //roleid = 1,
                        roleid        = (int)usertypeenum.seller,
                        user_type     = usertypeenum.seller.ToString(),
                        UsertableDTOs = null
                    };
                }
                else
                {
                    usertableview.usertype = new RoletypeDTO()
                    {
                        //roleid=2,
                        roleid        = (int)usertypeenum.customer,
                        user_type     = usertypeenum.customer.ToString(),
                        UsertableDTOs = null
                    };
                }
                //client.PostAsJsonAsync<>()
                var response = client.PostAsJsonAsync <UsertableView>(signupPostUrl, usertableview);
                response.Wait();
                var result = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    //Response.Write("Sign up successful");
                    isSignupSuccessful = true;
                    ViewBag.Message    = "Sign up successful";
                }
            }

            if (isSignupSuccessful == false)
            {
                ModelState.AddModelError("", "Error occured");
                Response.Write("Sign up not successful");
            }
            return(View(usertable));
        }