Beispiel #1
0
        private async Task <MenuResponseModel> GetMenuAsync(int id)
        {
            MenuResponseModel responseContent = null;

            using (HttpClient client = new HttpClient())
            {
                string actionPath = "Listing/GetMenu";
                client.BaseAddress = baseApiUrl;
                client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();
                MenuSearchModel msModel = new MenuSearchModel()
                {
                    CurrentPage  = 1,
                    ItemsPerPage = Int32.MaxValue,
                    SearchTerm   = "",
                    ItemId       = id
                };

                HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, msModel);

                if (response.IsSuccessStatusCode)
                {
                    responseContent = await response.Content.ReadAsAsync <MenuResponseModel>();
                }
            }
            return(responseContent);
        }
Beispiel #2
0
        private async Task <List <ItemTypeViewModel> > GetItemTypesAsync(ItemTypeViewModel itemTypeViewModel)
        {
            try
            {
                string        actionPath      = "Listing/GetCatogries";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());;
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //client.BaseAddress = new Uri(path);
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, itemTypeViewModel);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null && responseContent.Success)
                {
                    var json = JsonConvert.SerializeObject(responseContent.Data);
                    var itemsResponseModel = JsonConvert.DeserializeObject <List <ItemTypeViewModel> >(json);
                    return(itemsResponseModel);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
0
        public async Task <JsonResult> FetchDeliveryChargesAndTime(PlaceOrderRequestModelLocal userObj)
        {
            DeliveryChargesResponseModel responseContent = null;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    string actionPath = "order/estimatedDeliveryCharges";
                    client.BaseAddress = baseApiUrl;
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //validate the userobj before sending it fruther to prevent sql injections and stuff

                    //here

                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, userObj);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <DeliveryChargesResponseModel>();
                    }
                }
            }
            catch (Exception e)
            {
                //log ex here
                //throw;
            }



            return(Json(responseContent));
        }
Beispiel #4
0
        public async Task <JsonResult> PlaceOrder(PlaceOrderRequestModelLocal userObj)
        {
            PlaceOrderResponseModel responseContent = null;

            try
            {
                userObj.OrderPlacedById = User.Identity.GetUserId();
                userObj.FromWeb         = true;
                using (HttpClient client = new HttpClient())
                {
                    string actionPath = "order/place";
                    client.BaseAddress = baseApiUrl;
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, userObj);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <PlaceOrderResponseModel>();
                    }
                }
                System.Web.HttpContext.Current.Session["ConfirmedOrderSerialNo"] = responseContent.SerialNo;
            }
            catch (Exception e)
            {
                //log ex here
                //throw;
            }



            return(Json(responseContent));
        }
Beispiel #5
0
        public async Task <ActionResult> OrderConfirmed(List <string> OrderIds)
        {
            OrderConfirmedResponseModel responseContent = null;

            try
            {
                var OrderSerialNo = System.Web.HttpContext.Current.Session["ConfirmedOrderSerialNo"] as string;
                using (HttpClient client = new HttpClient())
                {
                    string actionPath = "order/getDetailsBySerialNo";
                    client.BaseAddress = baseApiUrl;
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();
                    OrderConfirmedRequestModel msModel = new OrderConfirmedRequestModel()
                    {
                        SerialNo = OrderSerialNo
                    };

                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, msModel);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <OrderConfirmedResponseModel>();
                    }
                }
            }
            catch (Exception e)
            {
                //log here
                //                throw;
            }

            return(View("~/Views/Cart/Confirmed/Index.cshtml", responseContent));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return Json(new { Success = false, Status = 5, Message = "Required data is missing" }, JsonRequestBehavior.AllowGet);
                //}
                string        actionPath      = "Account/Login";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //client.BaseAddress = new Uri(path);
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, model);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null)
                {
                    var json = JsonConvert.SerializeObject(responseContent.Data);
                    var itemsResponseModel = JsonConvert.DeserializeObject <UserModel>(json);
                    switch (responseContent.Code)
                    {
                    case 1:
                        var result = await SignInManager.PasswordSignInAsync(model.PhoneNumber, model.Password, model.RememberMe, shouldLockout : false);

                        return(Json(new { Success = true, Status = responseContent.Code, Message = "Login successful", Object = new { UserId = itemsResponseModel.Id != Guid.Empty ? itemsResponseModel.Id : itemsResponseModel.UserId } }, JsonRequestBehavior.AllowGet));

                    case 2:
                        return(Json(new { Success = true, Status = responseContent.Code, Message = "Please verify phone number", Object = new { UserId = itemsResponseModel.Id != Guid.Empty ? itemsResponseModel.Id : itemsResponseModel.UserId } }, JsonRequestBehavior.AllowGet));

                    case 3:
                        var user = UserManager.Find(model.PhoneNumber, model.Password);
                        return(Json(new { Success = false, Status = responseContent.Code, Message = "Invalid login type" }, JsonRequestBehavior.AllowGet));

                    case 4:
                    default:
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return(Json(new { Success = false, Status = responseContent.Code, Message = "Invalid phone number/password" }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new { Success = false, Status = 5, Message = "Something went wrong while login attempt" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Status = 5, Message = "Something went wrong while login attempt" }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <ActionResult> ResetPassword(VerifyPhoneNumberCustomeModel model)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return Json(new { Success = false, Message = "Either UserId or Code is empty" }, JsonRequestBehavior.AllowGet);
                //}
                string        actionPath      = "User/RequestResetPasswordWithCode";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //client.BaseAddress = new Uri(path);
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, model);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null && responseContent.Success)
                {
                    //var json = JsonConvert.SerializeObject(responseContent.Data);
                    //var itemsResponseModel = JsonConvert.DeserializeObject<UserModel>(json);
                    var user = UserManager.FindById(model.UserId);
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(Json(new { Success = responseContent.Success, Message = String.Join(" ", responseContent.Messages), Object = new { model.UserId } }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { Success = false, Message = String.Join(" ", responseContent.Messages) }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Message = "Something went wrong while reseting password" }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #8
0
        public async Task <JsonResult> UpdateUserInfo(UpdateUserInfoRequestModel userObj)
        {
            UserInfoInCartResponseModel responseContent = null;

            using (HttpClient client = new HttpClient())
            {
                string actionPath = "Account/UpdateProfile";
                client.BaseAddress = baseApiUrl;
                client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                //validate the userobj before sending it fruther to prevent sql injections and stuff

                //here

                HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, userObj);

                if (response.IsSuccessStatusCode)
                {
                    responseContent = await response.Content.ReadAsAsync <UserInfoInCartResponseModel>();
                }
            }

            return(Json(responseContent));
        }
Beispiel #9
0
        public async Task <ActionResult> Index()
        {
            UserInfoInCartResponseModel responseContent = null;

            using (HttpClient client = new HttpClient())
            {
                var    uid        = User.Identity.GetUserId();
                string actionPath = "Account/GetUserInfo";
                client.BaseAddress = baseApiUrl;
                client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();
                UserInfoRequestModel msModel = new UserInfoRequestModel()
                {
                    UserId = uid//"33669f22-43da-4f5d-b801-91ade07afc5d"
                };

                HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, msModel);

                if (response.IsSuccessStatusCode)
                {
                    responseContent = await response.Content.ReadAsAsync <UserInfoInCartResponseModel>();
                }
            }
            return(View(responseContent));
        }
        public async Task <ActionResult> ResendCode(GetPhoneNumberCodeModel model)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return Json(new { Success = false, Message = "Either UserId or Code is empty" }, JsonRequestBehavior.AllowGet);
                //}
                string        actionPath      = "account/GetPhoneNumberCode";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //client.BaseAddress = new Uri(path);
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, model);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null && responseContent.Success)
                {
                    //var json = JsonConvert.SerializeObject(responseContent.Data);
                    //var itemsResponseModel = JsonConvert.DeserializeObject<UserModel>(json);
                    return(Json(new { Success = responseContent.Success, Message = String.Join(" ", responseContent.Messages) }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { Success = false, Message = String.Join(" ", responseContent.Messages) }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Message = "Something went wrong while resending code on phone number" }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <JsonResult> Register(RegisterViewModel model)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return Json(new { Success = false, Status = 5, Message = "Required data is missing" }, JsonRequestBehavior.AllowGet);
                //}
                string        actionPath      = "Account/Registration";
                ResponseModel responseContent = null;
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(CommonFunction.GetWebAPIBaseURL());
                    client.DefaultRequestHeaders.Authorization = AuthHandler.AuthenticationHeader();

                    //client.BaseAddress = new Uri(path);
                    HttpResponseMessage response = await client.PostAsJsonAsync(actionPath, model);

                    if (response.IsSuccessStatusCode)
                    {
                        responseContent = await response.Content.ReadAsAsync <ResponseModel>();
                    }
                }
                if (responseContent != null && responseContent.Success)
                {
                    var json = JsonConvert.SerializeObject(responseContent.Data);
                    var itemsResponseModel = JsonConvert.DeserializeObject <UserModel>(json);
                    return(Json(new { Success = true, Message = "Registeration successful", Object = new { UserId = itemsResponseModel.Id != Guid.Empty ? itemsResponseModel.Id : itemsResponseModel.UserId, itemsResponseModel.PhoneNumber } }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { Success = false, Message = String.Join("\n", responseContent.Messages) }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Message = "Something went wrong while registration" }, JsonRequestBehavior.AllowGet));
            }
        }