public async Task <IActionResult> Profile() { string UserName = db.GetUserName(HttpContext); User user = await db.User.Include(p => p.Profile).ThenInclude(a => a.Address).FirstOrDefaultAsync(x => x.Login == UserName); if (user.Profile == null) { user.Profile = new UserProfile { Address = new Address() }; db.User.Update(user); await db.SaveChangesAsync(); } UserProfile profile = user.Profile; UserProfileViewModel model = new UserProfileViewModel { Login = user.Login, Email = user.Email, FirstName = profile.FirstName, SecondName = profile.SecondName, City = profile.Address.City, Street = profile.Address.Street, Building = profile.Address.Building, Flat = profile.Address.Flat, PostalCode = profile.Address.PostalCode }; return(View(model)); }
public async Task <ActionResult> CreateUserTemplate(int TemplateId) { Template template = await db.Template.Include(p => p.Product).FirstOrDefaultAsync(x => x.Id == TemplateId); if (template != null) { Template UserTemplate = new Template { Product = template.Product, JsonTemplate = template.JsonTemplate, DateCreated = DateTime.Now.ToShortDateString() }; string UserName = db.GetUserName(HttpContext); if (User.Identity.IsAuthenticated) { User user = await db.User.Include(t => t.Templates).FirstOrDefaultAsync(x => x.Login == UserName); user.Templates.Add(UserTemplate); db.User.Update(user); } else { UserTemplate.Name = UserName; await db.Template.AddAsync(UserTemplate); } await db.SaveChangesAsync(); return(RedirectToAction("Editor", "Editor", new { templateId = UserTemplate.Id })); } return(StatusCode(StatusCodes.Status404NotFound)); }
public async Task ChangeOrderStatus(int Status, int OrderId) { Order order = await db.Order.FirstOrDefaultAsync(x => x.OrderId == OrderId); order.Status = Status; db.Order.Update(order); await db.SaveChangesAsync(); }
public async Task MigrateCart(string userName) { string ShoppingCartId = db.GetUserName(HttpContext); var shoppingCart = db.Cart.Where(c => c.CartId == ShoppingCartId); foreach (Cart item in shoppingCart) { item.CartId = userName; } HttpContext.Session.SetString("CartId", userName); await db.SaveChangesAsync(); }
public async Task <IActionResult> AddToCart(int TemplateId) { Template UserTemplate = await db.Template.Include(p => p.Product).Include(u => u.User).FirstOrDefaultAsync(t => t.Id == TemplateId); if (UserTemplate != null) { string ShoppingCartId = db.GetUserName(HttpContext); if ((UserTemplate.User != null && UserTemplate.User.Login == ShoppingCartId) || UserTemplate.Name == ShoppingCartId) { Cart item = await db.Cart.FirstOrDefaultAsync(t => t.TemplateId == TemplateId && t.CartId == ShoppingCartId); if (item == null) { Cart cartItem = new Cart { CartId = ShoppingCartId, Template = UserTemplate, Quantity = 10, DateCreated = DateTime.Now, }; if (UserTemplate.Product.CategoryId == 9) { cartItem.Price = UserTemplate.Product.Price * 10; } else { cartItem.Price = 240.00M; cartItem.PaperId = 11; } await db.Cart.AddAsync(cartItem); await db.SaveChangesAsync(); } } } return(RedirectToAction("CartView", "ShoppingCart")); }
public async Task <IActionResult> OrderConfirm() { OrderConfirm model = new OrderConfirm(); if (User.Identity.IsAuthenticated) { string UserName = db.GetUserName(HttpContext); User user = await db.User.Include(p => p.Profile).ThenInclude(a => a.Address).FirstOrDefaultAsync(x => x.Login == UserName); if (user.Profile == null) { user.Profile = new UserProfile { Address = new Address() }; db.User.Update(user); await db.SaveChangesAsync(); } else { model = new OrderConfirm { Login = user.Login, Email = user.Email, FirstName = user.Profile.FirstName, SecondName = user.Profile.SecondName, City = user.Profile.Address.City, Street = user.Profile.Address.Street, Building = user.Profile.Address.Building, Flat = user.Profile.Address.Flat, PostalCode = user.Profile.Address.PostalCode }; } } return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Quantity,FileName,Printer,PrintDate,CompanyName,Type")] Print print) { if (print.Quantity <= 0) { return(NotFound("Vui lòng nhập số lượng files cần in")); } var curUser = await _userManager.GetUserAsync(User); if (curUser is null) { return(View("Error", "Bạn phải đăng nhập để thực hiện tác vụ này")); } var authorized = await IsAuthorized(curUser, "Prints", "Create"); if (!authorized) { return(View("AccessDenied")); } Guid tempCode = new Guid(); if (ModelState.IsValid) { Update(print, curUser); if (string.IsNullOrEmpty(print.Printer) || string.IsNullOrWhiteSpace(print.Printer)) { return(View("Error", "Vui lòng cập nhật họ tên để sử dụng tiếp tục sử dụng")); } var date = print.PrintDate.ToString("dd/MM/yyyy"); var lastName = curUser.Name.Split(" ").Last(); var printed = _context.Print.Where(e => e.Printer == lastName && e.PrintDate.ToString("dd/MM/yyyy") == date).Include(e => e.Files).FirstOrDefault(); var printer = print.Printer.Split(" ").Last(); int printedFiles = 0; if (printed != null) { printedFiles = printed.Quantity; if (print.Quantity + printedFiles > 100) { return(View("Error", $"Vui lòng nhập số lượng file nhỏ hơn {100 - printedFiles + 1}")); } printed.Quantity += print.Quantity; printed.PrintDate = print.PrintDate; for (int i = 0; i < print.Quantity; i++) { var index = (i + 1 + printedFiles).ToString("000"); var text = $"{printed.CompanyName}-{date}-{printer}-{index}"; printed.Files.Add(new Download { File = printed.FileName, QRCode = text, Image = GenerateQRCode(text) }); // var filePath = $"{Path.GetTempPath()}{text}.pdf"; // GenerateQRCode(text); //TODO add code to file // SaveFile(filePath); //TODO save file to google drive } tempCode = printed.Code; _context.Entry(printed).State = EntityState.Modified; } else { print.Files = new List <Download>(); var numberOfFiles = print.Quantity; if (numberOfFiles <= 0 || numberOfFiles > 100) { return(View("Error", "Invalid number of files{numberOfFiles}, it must be between 0 and 101")); } for (int i = 0; i < numberOfFiles; i++) { var index = (i + 1 + printedFiles).ToString("000"); var text = $"{print.CompanyName}-{date}-{printer}-{index}"; print.Files.Add(new Download { File = print.FileName, QRCode = text, Image = GenerateQRCode(text) }); // var filePath = $"{Path.GetTempPath()}{text}.pdf"; // GenerateQRCode(text); //TODO add code to file // SaveFile(filePath); //TODO save file to google drive } tempCode = print.Code; _context.Add(print); } await _context.SaveChangesAsync(); ViewBag.code = print.Code; string contents = "Dear Ms. Hương\n"; contents += $"Ngày {date} Hệ thống đã nhận được yêu cầu in {print.Quantity} Phiếu đăng ký giữ chỗ dự án Vinhomes Grand Park từ {curUser.Name}."; contents += "\nRegards.\n"; SendMail("Thông báo in hợp đồng", new MailboxAddress("Ms. Hương", "*****@*****.**"), contents); return(RedirectToAction("Download", new { code = tempCode })); } return(View("Error", $"Invalid model state {ModelState}!")); }