public AccountController(NavaraDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IUsersService userService) : base(userService) { _Context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, NavaraDbContext Context) { app.UseDirectoryBrowser(new DirectoryBrowserOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot")), RequestPath = new PathString() }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseMvc(); Context.Database.Migrate(); app.UseSignalR(routes => { routes.MapHub <ChatHub>("/chatHub"); }); //try //{ // var project = new Project // { // Name = "Test Project ", // Name2 = "مشروع تجريب", // Description = "this project for test and you dont need to see it so go away ", // Description2 = "هيدا المشروع للتجريب و انت ما بهمك يلا من هون", // }; // var Image = new ProjectImage { ImagePath = "Images/Course/batota.jpeg" }; // var Image2 = new ProjectImage { ImagePath = "Images/Course/batota.jpeg" }; // var Image3 = new ProjectImage { ImagePath = "Images/Course/batota.jpeg" }; // project.ProjectImages.Add(Image); // project.ProjectImages.Add(Image2); // project.ProjectImages.Add(Image3); // var itemes = Context.Items.Take(4).ToList(); // foreach (var item in itemes) // { // project.ProjectItems.Add(new ProjectItem { ItemID = item.ID, ProjectID = project.ID }); // } // Context.Projects.Add(project); // Context.SaveChanges(); //} //catch (Exception ex) //{ //} }
public GetChangesController(NavaraDbContext Context) { _Context = Context; }
public OffersController(NavaraDbContext context) : base(context) { }
public ItemCategoriesController(NavaraDbContext context) : base(context) { }
public ItemsController(NavaraDbContext context) : base(context) { }
public static async Task <string> CreatePDF(this Order order, IConverter converter, NavaraDbContext context) { try { string Root = "wwwroot"; string pdfFoler = $@"Orders"; if (!Directory.Exists(Path.Combine(Root, pdfFoler))) { Directory.CreateDirectory(Path.Combine(Root, pdfFoler)); } string pdfFile = Path.Combine(Root, pdfFoler, $"{order.Code}.pdf"); var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "Order " + order.Code, Out = pdfFile }; var orginal = context.Orders.Include("OrderItems").Include("OrderItems.Item") .Include("OrderItems.Item.ItemCategory").Include("Account") .Include("Account.User") .FirstOrDefault(x => x.ID == order.ID); var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = OrderTemplate(orginal), //WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Styles", "OrderStyle.css") }, HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Left = "Navara Store, Electronic store #1 in Syria" }, FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Invoice was created on a computer and is valid without the signature and seal." + "\r\nFor more details visit our website: www.navarastore.com" } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; converter.Convert(pdf); order.InvoicePath = Path.Combine(pdfFoler, $"{order.Code}.pdf"); await context.SubmitAsync(); return(order.InvoicePath); } catch (Exception ex) { return(""); } }
public OperationsController(NavaraDbContext context, IHostingEnvironment env) : base(context, env) { }
public CartController(NavaraDbContext context) : base(context) { }
public async Task <IActionResult> CreateOrder([FromBody] OrderModel model) { try { var userID = HttpContext.User.Identity.Name; if (userID == null) { return(StatusCode(StatusCodes.Status401Unauthorized)); } ApplicationUser user = await _context.Set <ApplicationUser>().SingleOrDefaultAsync(item => item.UserName == userID); if (user == null) { return(BadRequest("Token is not related to any Account")); } Account account = _context.Set <Account>().Include(x => x.Cart) .ThenInclude(x => x.CartItems).FirstOrDefault(x => x.ID == user.AccountID); if (user == null || account == null) { return(null); } //if (!user.IsVerified) return StatusCode(StatusCodes.Status426UpgradeRequired); Order order = new Order() { AccountID = account.ID, CreationDate = DateTime.Now, FromTime = DateTime.Parse(model.FromTime), ToTime = DateTime.Parse(model.ToTime), Location = model.Location, PromoCode = model.PromoCode, LocationRemark = model.LocationRemark, LocationText = model.LocationText, Mobile = model.Mobile, Remark = model.Remark, Name = model.Name, Status = OrderStatus.InProgress.ToString(), UseWallet = model.UseWallet, }; if (!string.IsNullOrEmpty(model.PromoCode)) { var Cash = _context.Set <CashOffer>().FirstOrDefault(s => s.PromoCode == model.PromoCode); if (Cash != null) { order.Discount = Cash.Percentge; } } foreach (var record in model.OrderItems) { if (record == null) { continue; } OrderItem orderItem = new OrderItem() { ItemID = record.OrderItemID, Quantity = record.Quantity, OfferID = record.OfferID }; order.OrderItems.Add(orderItem); if (account.Cart != null) { var item = account.Cart.CartItems.FirstOrDefault(x => x.ItemID == record.OrderItemID); if (item != null) { account.Cart.CartItems.Remove(item); } } } if (order.GenerateCode(_context as NavaraDbContext) == false) { return(BadRequest("Error while generating Order Code")); } if (order.UseWallet == true) { int amount = ((int)(account.Wallet / 100)) * 100; amount = Math.Min(amount, (account.Wallet as int?) ?? 0); account.Wallet -= amount; order.WalletAmount = amount; } this._context.Set <Order>().Add(order); await this._context.SaveChangesAsync(); Thread UpdateAllInfo = new Thread(async() => { using (var context = new NavaraDbContext()) { var orginalOrder = await context.Orders.Include("OrderItems").Include("Account").Include("Account.User") .Include("OrderItems.Item").Include("OrderItems.Offer").FirstOrDefaultAsync(x => x.ID == order.ID); await orginalOrder.FixMissingOfferItems(context); await orginalOrder.UpdateOrder(context); string pdfPath = await orginalOrder.CreatePDF(_converter, context as NavaraDbContext); #region Send Email to Support await EmailService.SendEmailToSupport($"New Order", $"Order # {orginalOrder.Code}\r\n" + $"Account: {orginalOrder.Account.Name}\r\n" + $"Amount: {orginalOrder.OrderItems.Sum(x => x.Total)}\r\n" + $"Date: {orginalOrder.CreationDate}\r\n" + $"Days To Deliver: {orginalOrder.DaysToDeliver}\r\n" + $"Items:\r\n{string.Join("\t | \t", orginalOrder.OrderItems.Select(x => x.Item?.Name + " : " + x.Quantity))}", Path.Combine("wwwroot", pdfPath)); string Mobile = "+" + order.Account.User.CountryCode + order.Account.User.PhoneNumber; if (!string.IsNullOrWhiteSpace(Mobile)) { string message = $"Thank you for choosing Navara Store\r\nYour Order had been recieved\r\nOrder Code: {order.Code}\r\nOrder invoice: {Path.Combine("http://api.navarastore.com/", pdfPath.Replace("\\", "/"))}"; SMSService.SendWhatsApp(message, Mobile); } #endregion } }); UpdateAllInfo.Start(); return(Json(new { OrderCode = order.Code, DaysToDeliver = order.DaysToDeliver })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public OrdersController(NavaraDbContext context, IConverter converter) : base(context) { _converter = converter; }