protected void BtnSubmit_Click(object sender, EventArgs e)
 {
     if (_userDao.IsAuthentic(TxtEmail.Text, TxtPassword.Text))
     {
         Logic.User usr = _userDao.Login(TxtEmail.Text, TxtPassword.Text);
         FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, usr.UserId.ToString(), DateTime.Now,
                                                                          DateTime.Now.AddMinutes(10), false, usr.Role == Role.USER ? "user" : "admin");
         string strTicket = FormsAuthentication.Encrypt(ticket);
         Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, strTicket));
         Response.Redirect(FormsAuthentication.GetRedirectUrl(usr.UserId.ToString(), false));
     }
 }
Beispiel #2
0
        public ActionResult MyCart()
        {
            var sh       = new Shop();
            var us       = new User();
            var product  = new ProductClass();
            var allCards = new List <Card>();

            using (var client = new HttpClient())
            {
                var task = client.GetAsync("https://localhost:44362/api/ShopApi/GetAllCards").ContinueWith(
                    taskwithresponse =>
                {
                    var response   = taskwithresponse.Result;
                    var jsonString = response.Content.ReadAsStringAsync();
                    jsonString.Wait();
                    allCards = JsonConvert.DeserializeObject <List <Card> >(jsonString.Result);
                }
                    );
                task.Wait();
                product.Cards = allCards;
            }

            var userid   = us.GetUserId(User.Identity.Name);
            var nameList = new List <Card>();

            foreach (var item in allCards)
            {
                if (item.Uploader == userid)
                {
                    var id   = item.ProductCodes.Split(',');
                    var temp = new StringBuilder();
                    foreach (var single in id)
                    {
                        if (single == "")
                        {
                            continue;
                        }
                        temp.Append("," + sh.GetProduct(single).Name);
                    }

                    var cr = new Card
                    {
                        Id       = item.Id, ProductQuantities = item.ProductQuantities, ProductCodes = temp.ToString(),
                        Uploader = item.Uploader
                    };
                    nameList.Add(cr);
                }
            }

            product.Cards = nameList;
            return(View(product));
        }
Beispiel #3
0
        public ActionResult AllCarts()
        {
            var product = new ProductClass {
                UserRole = role
            };

            using (var client = new WebClient())
            {
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                var data   = "=" + User.Identity.Name;
                var result = client.UploadString("https://localhost:44362/api/UserApi/GetUserRole", "POST", data);
                product.UserRole = result;
            }

            var allCards = new List <Card>();

            using (var client = new HttpClient())
            {
                var task = client.GetAsync("https://localhost:44362/api/ShopApi/GetAllCards").ContinueWith(
                    taskwithresponse =>
                {
                    var response   = taskwithresponse.Result;
                    var jsonString = response.Content.ReadAsStringAsync();
                    jsonString.Wait();
                    allCards = JsonConvert.DeserializeObject <List <Card> >(jsonString.Result);
                }
                    );
                task.Wait();
                var us = new Logic.User();
                foreach (var items in allCards)
                {
                    items.Uploader = us.GetUsername(items.Uploader);
                }
                product.Cards = allCards;
            }

            var nameList = new List <Card>();

            foreach (var item in allCards)
            {
                var id   = item.ProductCodes.Split(',');
                var temp = new StringBuilder();
                foreach (var single in id)
                {
                    if (single == "")
                    {
                        continue;
                    }
                    temp.Append("," + sh.GetProduct(single).Name);
                }

                var cr = new Card
                {
                    Id       = item.Id, ProductQuantities = item.ProductQuantities, ProductCodes = temp.ToString(),
                    Uploader = item.Uploader
                };
                nameList.Add(cr);
            }

            product.Cards = nameList;
            return(View(product));
        }
Beispiel #4
0
 public UserAssingnment(User u, List<Role> rls)
 {
     roles = rls;
     user = u;
 }