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)); }
public List <BillModelView> GetBills() { //get credential CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM); // get profile UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == credential.AccountUserName); // get all Bill with profileID from server List <BillModelView> bills = GetApiMyBills.GetBills(credential).Select(p => 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, }).ToList(); // get payment method foreach (var bill in bills) { bill.PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(p => p.PaymentMethodTypeId == bill.PaymentMethodId).PaymentMethodTypeName; } // get bill detail foreach (var item in bills) { List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == item.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(); item.BillDetail = details; // get delivery of bill DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == item.BillId); // get state of bill item.DeliveryProductStateId = delivery.DeliveryProductStateId; item.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName; } return(bills); }
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 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 Login(LoginModel login) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Common.Constants.BASE_URI); var postTask = client.PostAsJsonAsync <LoginModel>("LoginAuthentication/Authenticate", login); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { // get credential return var readTask = result.Content.ReadAsAsync <CredentialModel>(); readTask.Wait(); CredentialModel credential = readTask.Result; // get user profile UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.AccountId == Convert.ToInt32(credential.AccountId)); // get account && role Account account = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == profile.AccountId); account.AccountRole = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(p => p.AccountRoleId == account.AccountRoleId); profile.Account = account; credential.Profile = profile; // set 1 session for credential HttpContext.Session.SetObject("vm", 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()); }
public IActionResult ExistEmailValidate(string email) { if (!email.Contains("@")) { return(Content("exception-Email không khả dụng")); } else { if (GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == email) != null) { return(Content("exist-Email đã tồn tại")); } else { return(Content("available-Email khả dụng")); } } }
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); }
public IActionResult RatingDetail(string slugName) { IEnumerable <Product> products = GetApiProducts.GetProducts().Where(p => p.IsActivated == true); Product p = products.SingleOrDefault(p => p.SlugName == slugName); if (p == null) { return(RedirectToAction("Index", "NotFound")); } ProductModelViewDetail res = new ProductModelViewDetail() { ProductId = p.ProductId, ProductName = p.ProductName, ProductDescription = p.ProductDescription, ProductImage = p.ProductImage, ProductPrice = p.ProductPrice, ProductDiscount = p.ProductDiscount, CategoryName = GetApiCategories.GetCategories().SingleOrDefault(k => k.CategoryId == p.CategoryId).CategoryName, DistributorName = GetApiDistributors.GetDistributors().SingleOrDefault(k => k.DistributorId == p.DistributorId).DistributorName, Rating = getRatingProduct(p.ProductId), No_Ratings = GetApiUserComments.GetUserComments().Where(k => k.ProductId == p.ProductId && k.UserCommentApproved == true).Count(), InitAt = p.InitAt, Comments = new List <UserComment>() }; List <UserComment> comments = GetApiUserComments.GetUserComments().Where(k => k.ProductId == p.ProductId && k.UserCommentApproved == true).OrderByDescending(p => p.UserCommentPostedDate).ToList(); foreach (var cmt in comments) { cmt.UserProfile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileId == cmt.UserProfileId); } res.Comments = comments; return(View(res)); }
public IActionResult EditProfile(UserProfile profile, IFormFile avatarFile) { if (ModelState.IsValid) { //get user current UserProfile user = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == profile.UserProfileEmail); profile.AccountId = user.AccountId; profile.CustomerTypeId = user.CustomerTypeId; profile.UserProfileAvatar = user.UserProfileAvatar; if (avatarFile != null) { string extension = Path.GetExtension(avatarFile.FileName); if (SlugHelper.CheckExtension(extension)) { // delete img current var pathCurrent = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\avatar", profile.UserProfileAvatar); if (System.IO.File.Exists(pathCurrent)) { System.IO.File.Delete(pathCurrent); } string avatarName = Encryptor.RandomString(12); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images/avatar", avatarName + extension); using (var file = new FileStream(path, FileMode.Create)) { avatarFile.CopyTo(file); } profile.UserProfileAvatar = avatarName + extension; } else { ViewBag.error = "Kiểu file không hỗ trợ (jpg, png, ...)"; return(View("Index", profile)); } } CredentialModel credential = JsonConvert.DeserializeObject <CredentialModel>(HttpContext.Session.GetString("vm")); UserProfile update = UpdateProfile(profile); if (update != null) { // update sessionlogin credential.Profile = update; HttpContext.Session.SetObject("vm", credential); return(RedirectToAction("Index")); } else { ViewBag.error = "Cập nhật thất bại"; } } else { ViewBag.error = "Dữ liệu không thể để trống"; } return(View("Index", profile)); }
public IActionResult ExportExcel() { List <UserProfile> profiles = GetApiUserProfile.GetUserProfiles().ToList(); var stream = new MemoryStream(); using (var package = new ExcelPackage(stream)) { var worksheet = package.Workbook.Worksheets.Add("ProfilesData"); //custom format header worksheet.Row(1).Height = 20; worksheet.Column(1).Width = 5; worksheet.Column(2).Width = 30; worksheet.Column(3).Width = 30; worksheet.Column(4).Width = 30; worksheet.Column(5).Width = 20; worksheet.Column(6).Width = 20; worksheet.Row(1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; worksheet.Row(1).Style.Font.Bold = true; //custom color Color colFromHex = System.Drawing.ColorTranslator.FromHtml("#e8d39e"); for (int i = 1; i <= 6; i++) { worksheet.Cells[1, i].Style.Fill.PatternType = ExcelFillStyle.Solid; worksheet.Cells[1, i].Style.Fill.BackgroundColor.SetColor(colFromHex); } worksheet.Cells[1, 1].Value = "STT"; worksheet.Cells[1, 2].Value = "Email"; worksheet.Cells[1, 3].Value = "Tên khách hàng"; worksheet.Cells[1, 4].Value = "Ngày sinh"; worksheet.Cells[1, 5].Value = "Địa chỉ"; worksheet.Cells[1, 6].Value = "Số điện thoại"; //body of table int recordindex = 2; int idx = 1; foreach (var prof in profiles) { worksheet.Cells[recordindex, 1].Value = idx; worksheet.Cells[recordindex, 2].Value = prof.UserProfileEmail; worksheet.Cells[recordindex, 3].Value = prof.UserProfileFirstName + " " + prof.UserProfileMiddleName + " " + prof.UserProfileLastName; worksheet.Cells[recordindex, 4].Value = prof.UserProfileDob != null?DateTime.Parse(prof.UserProfileDob).ToString("dd/MM/yyyy") : "_"; worksheet.Cells[recordindex, 5].Value = prof.UserProfileAddress != null ? prof.UserProfileAddress : "_"; worksheet.Cells[recordindex, 6].Value = prof.UserProfilePhoneNumber != null ? prof.UserProfilePhoneNumber : "_"; worksheet.Row(recordindex).Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; worksheet.Row(recordindex).Style.Font.Bold = false; idx++; recordindex++; } package.Save(); } stream.Position = 0; return(File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ProfilesData.xlsx")); }
public IActionResult LoginExternal(string loginEx) { Account createdAccount = null; UserProfile userProfile = null; LoginEx login = JsonConvert.DeserializeObject <LoginEx>(loginEx); if (login.Email == null) { login.Email = "customer_" + Encryptor.RandomString(6) + "@petshop.com"; } UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == login.Email); // create if null if (profile == null) { string passwordTemp = Encryptor.RandomString(12); // create account RegisterModel register = new RegisterModel() { Email = login.Email, FirstName = login.FirstName, MiddleName = login.MiddleName, LastName = login.LastName, Password = passwordTemp, IsLoginExternal = true, DOB = "1990/1/1", Avatar = "noimage.png" }; createdAccount = CreateAccount(register); // create profile userProfile = CreateProfile(createdAccount, register); // create user score CreateUserScore(userProfile); } // request token login using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(Constants.BASE_URI); var postTask = client.PostAsJsonAsync <LoginEx>("LoginAuthentication/AuthenticateExternal", login); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <CredentialModel>(); readTask.Wait(); CredentialModel response = readTask.Result; // get user profile UserProfile res_profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.AccountId == Convert.ToInt32(response.AccountId)); // get account && role Account account = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == profile.AccountId); account.AccountRole = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(p => p.AccountRoleId == account.AccountRoleId); profile.Account = account; response.Profile = profile; // set 1 session for credential HttpContext.Session.SetObject("vm", response); return(RedirectToAction("Index", "Home")); } else { return(View()); } } }
public bool ExistEmail(string email) { return(GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == email) != null); }