public IActionResult ChangePassword(string pass1, string pass2)
        {
            if (pass1 != pass2)
            {
                ViewBag.result += @"Mật khẩu không khớp <br>";
            }
            if (pass1.Length < 6)
            {
                ViewBag.result += @"Mật khẩu chưa đủ mạnh";
            }
            if (pass1.Length >= 6 && pass2.Length >= 6 && pass1 == pass2)
            {
                CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
                string           token      = credential.JwToken;
                AccountManage    profile    = GetApiAccountManage.GetAccountManages(credential.JwToken).SingleOrDefault(p => p.Email == credential.Email);
                profile.Password = Encryptor.MD5Hash(pass1);
                using (HttpClient client = HelperClient.GetClient(token))
                {
                    client.BaseAddress = new Uri(Constants.BASE_URI);

                    var putTask = client.PutAsJsonAsync <AccountManage>(Constants.ACCOUNT_MANAGE + "/" + profile.Email, profile);
                    putTask.Wait();
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View("ChangePassword"));
        }
Beispiel #2
0
        public IActionResult Login(LoginModel login)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <LoginModel>("LoginAuthentication/AuthenticateManage", login);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    // get credential return
                    var readTask = result.Content.ReadAsAsync <CredentialManage>();
                    readTask.Wait();
                    CredentialManage credential = readTask.Result;

                    // set 1 session for credential
                    HttpContext.Session.SetObject(Constants.VM_MANAGE, credential);

                    if (login.returnUrl != null)
                    {
                        return(Redirect(login.returnUrl));
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.error = "Tài khoản hoặc mật khẩu không đúng";
                }
            }

            return(View("Index"));
        }
Beispiel #3
0
        private Product CreatedProduct(Product product)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <Product>(Constants.PRODUCT, product);
                postTask.Wait();

                var result = postTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Product>();
                    readTask.Wait();

                    return(readTask.Result);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #4
0
        public static IEnumerable <Bill> GetBills(CredentialManage credential)
        {
            IEnumerable <Bill> bills = null;

            using (var client = Common.HelperClient.GetClient(credential.JwToken))
            {
                client.BaseAddress = new Uri(Constants.BASE_URI);
                var responseTask = client.GetAsync(Constants.BILL);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IList <Bill> >();
                    readTask.Wait();

                    bills = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    bills = Enumerable.Empty <Bill>();
                }
            }

            return(bills);
        }
Beispiel #5
0
        public IActionResult Earning7Days(int days)
        {
            List <Earning7Day> earning7Days = new List <Earning7Day>();
            CredentialManage   credential   = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <DateTime>    dateTimes    = new List <DateTime>();
            DateTime           now          = DateTime.Now.Date;

            for (int i = 0; i < days; i++)
            {
                dateTimes.Add(now);
                now = now.AddDays(-1);
            }

            dateTimes = dateTimes.OrderBy(p => p).ToList();

            // get data
            foreach (var date in dateTimes)
            {
                earning7Days.Add(new Earning7Day()
                {
                    Label = date.ToString("dd/MM/yyyy"),
                    Data  = GetBills(credential).Where(p => p.DateOfPurchase.Date == date).Sum(p => p.TotalPrice)
                });
            }

            return(Json(earning7Days));
        }
Beispiel #6
0
        public IActionResult UpdateDeliveryState(string billCode, int stateId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            Bill             bill       = GetApiBills.GetBills(credential).SingleOrDefault(p => p.GenerateCodeCheck == billCode);
            DeliveryProduct  delivery   = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId);

            delivery.DeliveryProductStateId = stateId;

            if (GetApiDeliveryStates.GetDeliveryProductStates()
                .SingleOrDefault(p => p.DeliveryProductStateId == stateId).DeliveryProductStateName == "Đã giao hàng")
            {
                bill.IsCompleted     = true;
                bill.DateOfDelivered = DateTime.Now;
                GetApiBills.Update(bill, credential.JwToken);
            }

            GetApiDeliveryProducts.Update(delivery, credential.JwToken);

            // sender mail
            UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileId == bill.UserProfileId);

            string body = "Đơn hàng có mã #" + bill.GenerateCodeCheck + " đã cập nhật trạng thái vận chuyển mới: " +
                          GetApiDeliveryStates.GetDeliveryProductStates()
                          .SingleOrDefault(p => p.DeliveryProductStateId == stateId).DeliveryProductStateName;

            SenderEmail.SendMail(profile.UserProfileEmail, "PETSHOP: UPDATE DELIVERY STATE'S YOUR BILL", body);
            return(Json(bill));
        }
Beispiel #7
0
        public IActionResult InventoryReceivingNotes()
        {
            CredentialManage credential = JsonConvert
                                          .DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <InventoryReceivingNote> notes = GetApiInventoryReceiveNotes
                                                  .GetInventoryReceivingNotes(credential.JwToken).ToList();

            return(View(notes));
        }
Beispiel #8
0
        private void UpdateIsRead(int feedbackId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            Feedback         feedback   = GetApiFeedbacks.GetFeedbacks(credential.JwToken).SingleOrDefault(p => p.FeedbackId == feedbackId);

            // update
            feedback.IsRead = !feedback.IsRead;
            GetApiFeedbacks.Update(feedback, credential.JwToken);
        }
        public IActionResult VerifyPassword(AccountProfilePassword profile)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            profile.Email = credential.Email;
            if (GetApiAccountManage.GetAccountManages(credential.JwToken).Any(p => p.Email == profile.Email && p.Password == Encryptor.MD5Hash(profile.Password)))
            {
                return(RedirectToAction("ChangePassword"));
            }
            ViewBag.result = "Sai thông tin đăng nhập";
            return(View());
        }
Beispiel #10
0
        public IActionResult DeActiveAccount(int accountId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            Account          account    = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == accountId);

            account.IsActive = !account.IsActive;

            // update
            GetApiAccounts.Update(account, credential.JwToken);

            return(RedirectToAction("Index"));
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            CredentialManage credential = HttpContext.Session.GetObject <CredentialManage>(Constants.VM_MANAGE);

            if (credential.AccountRoleName != Constants.ADMIN)
            {
                filterContext.Result = new RedirectToRouteResult(new
                                                                 RouteValueDictionary(new { controller = "NotFound", action = "Index" }));
            }

            base.OnActionExecuting(filterContext);
        }
Beispiel #12
0
        public IActionResult UpdateAllIsRead()
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <Feedback>  feedbacks  = GetApiFeedbacks.GetFeedbacks(credential.JwToken).ToList();

            foreach (var feedback in feedbacks)
            {
                feedback.IsRead = true;
                GetApiFeedbacks.Update(feedback, credential.JwToken);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #13
0
        // chart by filter

        public IActionResult BillsFilter(string from, string to)
        {
            DateTime fromValue = new DateTime();
            DateTime toValue   = new DateTime();

            if (from == "nodata" && to == "nodata")
            {
                fromValue = DateTime.Now.AddDays(-6);
                toValue   = DateTime.Now;
            }
            else if (from == "nodata" && to != "nodata")
            {
                fromValue = DateTime.Parse(to).AddDays(-6);
                toValue   = DateTime.Parse(to);
            }
            else if (from != "nodata" && to == "nodata")
            {
                fromValue = DateTime.Parse(from);
                toValue   = DateTime.Parse(from).AddDays(6);
            }
            else
            {
                fromValue = DateTime.Parse(from);
                toValue   = DateTime.Parse(to);
            }

            List <Earning7Day> BillsFilter = new List <Earning7Day>();
            CredentialManage   credential  = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <DateTime>    dateTimes   = new List <DateTime>();
            int days = (toValue.Date - fromValue.Date).Days + 1;

            for (int i = 0; i < days; i++)
            {
                dateTimes.Add(fromValue.Date);
                fromValue = fromValue.AddDays(1);
            }

            dateTimes = dateTimes.OrderBy(p => p).ToList();

            // get data
            foreach (var date in dateTimes)
            {
                BillsFilter.Add(new Earning7Day()
                {
                    Label = date.ToString("dd/MM/yyyy"),
                    Data  = GetBills(credential).Where(p => p.DateOfPurchase.Date == date).Count()
                });
            }

            return(Json(BillsFilter));
        }
Beispiel #14
0
        public IActionResult PaymentMethodFilter(string from = "nodata", string to = "nodata")
        {
            DateTime fromValue = new DateTime();
            DateTime toValue   = new DateTime();

            if (from == "nodata" && to == "nodata")
            {
                fromValue = DateTime.Now.AddDays(-6);
                toValue   = DateTime.Now;
            }
            else if (from == "nodata" && to != "nodata")
            {
                fromValue = DateTime.Parse(to).AddDays(-6);
                toValue   = DateTime.Parse(to);
            }
            else if (from != "nodata" && to == "nodata")
            {
                fromValue = DateTime.Parse(from);
                toValue   = DateTime.Parse(from).AddDays(6);
            }
            else
            {
                fromValue = DateTime.Parse(from);
                toValue   = DateTime.Parse(to);
            }

            List <Earning7Day> paymentMethod7Days = new List <Earning7Day>();
            CredentialManage   credential         = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <string>      paymentMethod      = new List <string>();

            foreach (var p in GetApiPaymentMethodTypes.GetPaymentMethodTypes())
            {
                paymentMethod.Add(p.PaymentMethodTypeName);
            }

            // get data
            foreach (var payment in paymentMethod)
            {
                paymentMethod7Days.Add(new Earning7Day()
                {
                    Label = payment,
                    Data  = GetBills(credential).Where(p => p.PaymentMethodTypeId == GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeName == payment).PaymentMethodTypeId&&
                                                       (p.DateOfPurchase.Date >= fromValue.Date) &&
                                                       (p.DateOfPurchase.Date <= toValue.Date)).Count()
                });
            }

            return(Json(paymentMethod7Days.OrderBy(p => p.Label).ToList()));
        }
Beispiel #15
0
        public List <UserProfile> GetProfiles(bool isActive = true)
        {
            CredentialManage   credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <UserProfile> profiles   = GetApiUserProfile.GetUserProfiles()
                                            .Where(p => GetApiAccounts.GetAccounts().SingleOrDefault(k => k.AccountId == p.AccountId) != null)
                                            .ToList();

            foreach (var prof in profiles)
            {
                Account account = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == prof.AccountId);
                prof.Account = account;
            }

            return(profiles);
        }
        public IActionResult UpdateProfile(string email, AccountManage profileInput, IFormFile Avatar)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            string           token      = credential.JwToken;
            AccountManage    profile    = GetApiAccountManage.GetAccountManages(credential.JwToken)
                                          .Select(p => new AccountManage()
            {
                Email         = p.Email,
                AccountRoleId = p.AccountRoleId,
                FullName      = profileInput.FullName,
                IsActivated   = p.IsActivated,
                Avatar        = p.Avatar,
                Address       = profileInput.Address,
                Password      = p.Password
            }).SingleOrDefault(p => p.Email == email);

            string accountImg = Encryptor.RandomString(12);
            string extension  = Avatar != null?Path.GetExtension(Avatar.FileName) : "";

            if (Avatar != null)
            {
                if (SlugHelper.CheckExtension(extension))
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images/avatar", accountImg + extension);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        Avatar.CopyTo(file);
                    }
                    profile.Avatar = accountImg + extension;
                }
                else
                {
                    ModelState.AddModelError("", Constants.EXTENSION_IMG_NOT_SUPPORT);
                    return(Content(Constants.EXTENSION_IMG_NOT_SUPPORT));
                }
            }

            using (HttpClient client = HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Constants.BASE_URI);

                var putTask = client.PutAsJsonAsync <AccountManage>(Constants.ACCOUNT_MANAGE + "/" + profile.Email, profile);
                putTask.Wait();

                var result = putTask.Result;
                return(View());
            }
        }
Beispiel #17
0
        public IActionResult ApproveBill(int billId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            Bill bill = GetApiBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId);

            // update
            bill.IsApprove  = true;
            bill.IsDelivery = true;

            if (Directory.Exists(Constants.EMBEDED_MAIL_URL) && System.IO.File.Exists(Constants.EMBEDED_MAIL_URL + bill.GenerateCodeCheck + ".png"))
            {
                // get credential
                string token = credential.JwToken;

                using (HttpClient client = Common.HelperClient.GetClient(token))
                {
                    client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                    var postTask = client.PutAsJsonAsync <Bill>(Constants.BILL + "/" + bill.BillId, bill);
                    postTask.Wait();

                    var result = postTask.Result;

                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <Bill>();
                        readTask.Wait();

                        // send email
                        UserProfile user = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileId == bill.UserProfileId);

                        SenderEmail.SendMail(user.UserProfileEmail, "PETSHOP Hóa đơn #" + bill.GenerateCodeCheck, "Đơn hàng có mã: #" + bill.GenerateCodeCheck + " vừa được duyệt", bill.GenerateCodeCheck);

                        return(Json(readTask.Result));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                return(NoContent());
            }
        }
        public IActionResult Index()
        {
            CredentialManage        credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <AccountManageDTO> accounts   = GetApiAccountManage.GetAccountManages(credential.JwToken)
                                                 .Select(p => new AccountManageDTO()
            {
                Email           = p.Email,
                AccountRoleName = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(k => k.AccountRoleId == p.AccountRoleId).AccountRoleName,
                Password        = p.Password,
                FullName        = p.FullName,
                IsActivated     = p.IsActivated,
                Avatar          = p.Avatar,
                Address         = p.Address
            }).ToList();

            return(View(accounts));
        }
Beispiel #19
0
        public IActionResult BillDetail(int billId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            Bill          p    = GetApiBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId);
            BillModelView bill = new BillModelView()
            {
                BillId            = p.BillId,
                BillCode          = p.GenerateCodeCheck,
                DateOfPurchase    = p.DateOfPurchase,
                DateDelivery      = Convert.ToDateTime(p.DateOfDelivered),
                TotalPrice        = p.TotalPrice,
                PaymentMethodId   = p.PaymentMethodTypeId,
                IsDelivery        = p.IsDelivery,
                IsCancel          = p.IsCancel,
                IsApprove         = p.IsApprove,
                IsCompleted       = p.IsCompleted,
                PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeId == p.PaymentMethodTypeId).PaymentMethodTypeName,
            };

            List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == bill.BillId)
                                             .Select(p => new BillDetailModel()
            {
                ProductId   = p.ProductId,
                ProductName = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductName,
                Amount      = p.ProductAmount,
                Price       = p.ProductPriceCurrent,
                NoteSize    = p.NoteSize,
                Image       = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductImage,
            }).ToList();

            bill.BillDetail = details;

            // get delivery
            DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId);

            bill.delivery = delivery;

            // get state of bill
            bill.DeliveryProductStateId = delivery.DeliveryProductStateId;

            bill.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName;

            return(Json(bill));
        }
Beispiel #20
0
        private void CreateAmountToys(int productId)
        {
            ToyProduct toy = new ToyProduct()
            {
                ProductId = productId,
                ToyAmount = 0
            };

            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            string           token      = credential.JwToken;

            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);
                var postTask = client.PostAsJsonAsync <ToyProduct>(Constants.TOY_PRODUCT, toy);
                postTask.Wait();
            }
        }
Beispiel #21
0
        private void CreateAmountFood(int productId)
        {
            FoodProduct food = new FoodProduct()
            {
                ProductId       = productId,
                FoodAmount      = 0,
                FoodExpiredDate = DateTime.MaxValue
            };

            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            string           token      = credential.JwToken;

            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);
                var postTask = client.PostAsJsonAsync <FoodProduct>(Constants.FOOD_PRODUCT, food);
                postTask.Wait();
            }
        }
        public IActionResult UpdateProfile(string email)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            AccountManage    profile    = GetApiAccountManage.GetAccountManages(credential.JwToken)
                                          .Select(p => new AccountManage()
            {
                Email         = p.Email,
                AccountRoleId = p.AccountRoleId,
                FullName      = p.FullName,
                IsActivated   = p.IsActivated,
                Avatar        = p.Avatar,
                Address       = p.Address
            }).SingleOrDefault(p => p.Email == email);

            ViewBag.AccountRoleName = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(k => k.AccountRoleId == profile.AccountRoleId).AccountRoleName;
            ViewBag.Email           = profile.Email;
            ViewBag.FullName        = profile.FullName;
            ViewBag.DiaChi          = profile.Address;
            return(View());
        }
Beispiel #23
0
        public IActionResult ChangeActivated(int productId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            Product current = GetApiProducts.GetProducts().SingleOrDefault(p => p.ProductId == productId);

            // update status
            current.IsActivated = !current.IsActivated;

            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PutAsJsonAsync <Product>(Constants.PRODUCT + "/" + current.ProductId, current);
                postTask.Wait();

                var result = postTask.Result;
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult ActivateAccount(string accountEmail)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            AccountManage acc = GetApiAccountManage.GetAccountManages(token).SingleOrDefault(p => p.Email == accountEmail);

            // update status
            acc.IsActivated = !acc.IsActivated;

            using (HttpClient client = HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Constants.BASE_URI);

                var putTask = client.PutAsJsonAsync <AccountManage>(Constants.ACCOUNT_MANAGE + "/" + acc.Email, acc);
                putTask.Wait();

                var result = putTask.Result;
            }

            return(RedirectToAction("Index"));
        }
Beispiel #25
0
        public List <BillViewModel> getBills()
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            List <BillViewModel> bills = GetApiBills.GetBills(credential).Select(p => new BillViewModel()
            {
                BillId                 = p.BillId,
                UserProfileEmail       = GetApiUserProfile.GetUserProfiles().SingleOrDefault(k => k.UserProfileId == p.UserProfileId).UserProfileEmail,
                DateOfPurchase         = p.DateOfPurchase,
                CurrentDeliveryState   = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(h => h.DeliveryProductStateId == GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(k => k.DeliveryProductBillId == p.BillId).DeliveryProductStateId).DeliveryProductStateName,
                IsDelivery             = p.IsDelivery,
                DateOfDelivered        = p.DateOfDelivered,
                GenerateCodeCheck      = p.GenerateCodeCheck,
                PaymentMethodName      = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeId == p.PaymentMethodTypeId).PaymentMethodTypeName,
                IsCancel               = p.IsCancel,
                TotalPrice             = p.TotalPrice,
                IsApprove              = p.IsApprove,
                IsCompleted            = p.IsCompleted,
                CurrentDeliveryStateId = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(k => k.DeliveryProductBillId == p.BillId).DeliveryProductStateId
            }).ToList();

            return(bills);
        }
Beispiel #26
0
        public IActionResult PaymentMethod7Days(int days)
        {
            List <Earning7Day> paymentMethod7Days = new List <Earning7Day>();
            CredentialManage   credential         = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <string>      paymentMethod      = new List <string>();

            foreach (var p in GetApiPaymentMethodTypes.GetPaymentMethodTypes())
            {
                paymentMethod.Add(p.PaymentMethodTypeName);
            }

            // get data
            foreach (var payment in paymentMethod)
            {
                paymentMethod7Days.Add(new Earning7Day()
                {
                    Label = payment,
                    Data  = GetBills(credential).Where(p => p.PaymentMethodTypeId == GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeName == payment).PaymentMethodTypeId&& (DateTime.Now.Date - p.DateOfPurchase.Date).Days < days).Count()
                });
            }

            return(Json(paymentMethod7Days.OrderBy(p => p.Label).ToList()));
        }
Beispiel #27
0
        private void CreateAmountCostume(int productId)
        {
            List <CostumeProduct> costumes = new List <CostumeProduct>();

            costumes.Add(new CostumeProduct()
            {
                ProductId         = productId,
                CostumeSize       = Constants.S,
                CostumeAmountSize = 0
            });
            costumes.Add(new CostumeProduct()
            {
                ProductId         = productId,
                CostumeSize       = Constants.M,
                CostumeAmountSize = 0
            });
            costumes.Add(new CostumeProduct()
            {
                ProductId         = productId,
                CostumeSize       = Constants.L,
                CostumeAmountSize = 0
            });

            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            string           token      = credential.JwToken;

            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                foreach (var p in costumes)
                {
                    var postTask = client.PostAsJsonAsync <CostumeProduct>(Constants.COSTUME_PRODUCT, p);
                    postTask.Wait();
                }
            }
        }
        public IActionResult ResetPassword(string accountEmail)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            AccountManage acc = GetApiAccountManage.GetAccountManages(token).SingleOrDefault(p => p.Email == accountEmail);


            string newPassword = Encryptor.RandomString(6);

            acc.Password = Encryptor.MD5Hash(newPassword);

            using (HttpClient client = HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Constants.BASE_URI);
                var putTask = client.PutAsJsonAsync <AccountManage>(Constants.ACCOUNT_MANAGE + "/" + acc.Email, acc);
                putTask.Wait();
                var result = putTask.Result;
            }
            //send Email
            SenderEmail.SendMail(accountEmail, "PETSHOP - Reset Your Password", String.Format("Your new password is here {0} please check it", newPassword));

            return(NoContent());
        }
Beispiel #29
0
 private List <Bill> GetBills(CredentialManage credential)
 {
     return(GetApiBills.GetBills(credential).Where(p => p.IsCancel == false).ToList());
 }
Beispiel #30
0
        public IActionResult EditProduct(int id, Product product, IFormFile productFile)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            Product current = GetApiProducts.GetProducts().SingleOrDefault(p => p.ProductId == id);

            Product update = new Product()
            {
                ProductId          = id,
                ProductName        = product.ProductName,
                ProductDescription = product.ProductDescription,
                ProductPrice       = product.ProductPrice,
                ProductDiscount    = product.ProductDiscount,
                NumberOfPurchases  = current.NumberOfPurchases,
                CategoryId         = product.CategoryId,
                DistributorId      = product.DistributorId,
                IsActivated        = true,
                SlugName           = SlugHelper.GetFriendlyTitle(product.ProductName),
                InitAt             = current.InitAt
            };

            // product img
            string productImg = Encryptor.RandomString(12);
            string extension  = productFile != null?Path.GetExtension(productFile.FileName) : "";

            if (productFile != null)
            {
                if (SlugHelper.CheckExtension(extension))
                {
                    update.ProductImage = productImg + extension;
                }
                else
                {
                    ViewBag.error = Constants.EXTENSION_IMG_NOT_SUPPORT;
                    return(View());
                }
            }
            else
            {
                update.ProductImage = current.ProductImage;
            }



            using (HttpClient client = Common.HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PutAsJsonAsync <Product>(Constants.PRODUCT + "/" + update.ProductId, update);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    // save img
                    if (productFile != null)
                    {
                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images/products", productImg + extension);
                        using (var file = new FileStream(path, FileMode.Create))
                        {
                            productFile.CopyTo(file);
                        }
                    }

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Chỉnh sửa thất bại");
                    return(View());
                }
            }
        }