Beispiel #1
0
        public int RegisterUser(User user)
        {
            try
            {
                var count = (from users in dbContext.NfUser
                             where users.Email == user.Email
                             select users).Count();
                if (count == 0)
                {
                    NfUser newUser = new NfUser();
                    newUser.FirstName     = user.FirstName;
                    newUser.LastName      = user.LastName;
                    newUser.Email         = user.Email;
                    newUser.Password      = user.Password;
                    newUser.IsActive      = true;
                    newUser.PasswordHash  = "";
                    newUser.SecurityStamp = "";

                    dbContext.Add(newUser);
                    dbContext.SaveChanges();

                    user.Id = newUser.UserId;
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
        public int AddToCart(CartModel model)
        {
            try
            {
                var item = (from cart in dbContext.ScUserCart
                            where cart.UserId == model.UserId && cart.ItemId == model.ItemId
                            select cart).FirstOrDefault();
                if (item != null)
                {
                    ScUserCart userCart = dbContext.ScUserCart.Find(item.UserCartId);

                    userCart.UserCartId = userCart.UserCartId;
                    userCart.UserId     = model.UserId;
                    userCart.ItemId     = model.ItemId;
                    userCart.Quantity   = item.Quantity + model.Quantity;

                    dbContext.Entry(userCart).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    dbContext.SaveChanges();

                    model.UserCartId = userCart.UserCartId;
                }
                else
                {
                    ScUserCart newCart = new ScUserCart();
                    newCart.UserId   = model.UserId;
                    newCart.ItemId   = model.ItemId;
                    newCart.Quantity = model.Quantity;
                    dbContext.Add(newCart);
                    dbContext.SaveChanges();
                    model.UserCartId = newCart.UserCartId;
                }
                return(model.UserCartId);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
        public int AddItem(ItemsModel model)
        {
            try
            {
                var list = (from Items in dbContext.ScItems
                            where Items.Description == model.Description && Items.ItemCategoryId == model.ItemCategoryId
                            select Items).Count();
                if (list == 0)
                {
                    ScItems newItem = new ScItems();

                    newItem.ItemCategoryId = model.ItemCategoryId;
                    newItem.Description    = model.Description;
                    newItem.Price          = model.Price;
                    newItem.DisplayOrder   = model.DisplayOrder;
                    newItem.IsInOffer      = model.IsInOffer;
                    newItem.OfferValidFrom = model.OfferValidFrom;
                    newItem.OfferValidTo   = model.OfferValidTo;
                    newItem.OfferPrice     = model.OfferPrice;

                    dbContext.Add(newItem);
                    dbContext.SaveChanges();
                    model.ItemId = newItem.ItemId;

                    return(newItem.ItemId);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
 public void AddProduct(Product p)
 {
     _context.Products.Add(p);
     _context.SaveChanges();
 }
Beispiel #5
0
        public bool PaymentConf(PaymentConformation payments)
        {
            //int orderID = 0;

            payconf = payments;

            try
            {
                if (payments != null)
                {
                    using (var context = new ShoppingCartDBContext(ShoppingCartDBContext.optionBuild.dbOption))
                    {
                        //// foreach (var pay in payments) {
                        var order = new Order();
                        {
                            order.DateTime  = payments.datetime;
                            order.Total     = payments.total;
                            order.customers = context.Customers.First(c => c.CustomerId == payments.customerId);
                            // order.Payments = context.Payments.First(p =>p.PayamentId == payments.P);
                            ////payment
                            context.Orders.Add(order);
                            context.SaveChanges();
                        }

                        CartItemModel cartItem = new CartItemModel();

                        int orderID = order.OrderId;

                        var cutomerName = context.Customers.First(c => c.CustomerId == payments.customerId);

                        foreach (var ordersdetail in payments.cartItemModel)
                        {
                            OrderDetail orderDetail = new OrderDetail();
                            {
                                orderDetail.UnitPrice = ordersdetail.unitPrice;
                                orderDetail.Quantity  = ordersdetail.quantity;
                                orderDetail.discount  = ordersdetail.discount;
                                //
                                // orderDetail.product = context.products.First(o => o.ProductId == cartItem.productId );
                                orderDetail.product = context.products.First(o => o.ProductId == ordersdetail.productId);
                                orderDetail.orders  = context.Orders.First(o => o.OrderId == orderID);

                                context.OrderDetails.Add(orderDetail);
                                context.SaveChanges();
                            };

                            int orderItemId = orderDetail.OrderDtailId;
                        }

                        Payment payment = new Payment();
                        {
                            payment.Amount        = payments.total;
                            payment.PaymentMethod = payments.paymentMethod;
                            payment.order         = context.Orders.FirstOrDefault(x => x.OrderId == orderID);
                            context.Payments.Add(payment);
                            context.SaveChanges();
                        }
                    }



                    // MailMessage msg = new MailMessage();
                    // message.From = new MailAddress(Session["Email"].Tostring());
                    // message.To.Add(ConfigurationSettings.AppSettings["RequesEmail"].ToString());
                    // msg.Subject = "Shopping Cart Oder Details ";
                    // msg.IsBodyHtml = true;

                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.Subject = "Shopping Cart Order  ";
                    mail.From    = new MailAddress("*****@*****.**");
                    mail.To.Add("*****@*****.**");
                    mail.Subject = "Shopping Cart";

                    foreach (var pay in payments.cartItemModel)
                    {
                        ProductId   = pay.productId;
                        ProductName = pay.productName;
                        UnitPrice   = pay.unitPrice;
                        Quantity    = pay.quantity;
                    }


                    string textBody = "" +
                                      "<h4>Customer Name</h4><span>" + payments.customerId + "</span><span><h4>Address</h4>" + payments.deliveryAddress + "</span></br>" +
                                      "<span><h4>Date</h4>" + payments.datetime + "</span></br>" +
                                      "<span><h4>Payment Method</h4>" + payments.paymentMethod + "</span></br>" +
                                      "<span><h4>Payment Amount</h4>" + payments.total + "</span></br>" +
                                      "<table border=" + 1 + " cellpadding=" + 0 + " cellspacing=" + 0 + " width = " + 400 + "><tr bgcolor='#4da6ff'><th><b>Product Id</b></th> <th> <b> Product Name </b> </th> <th> <b> Quantity </b> </th> <th> <b> UnitPrice </b> </th></tr>";// +

                    foreach (var pay in payments.cartItemModel)
                    {
                        textBody += "<tr>" +
                                    "<td>" + pay.productId + "</td>" +
                                    "<td>" + pay.productName + "</td>" +
                                    "<td>" + pay.unitPrice + "</td>" +
                                    "<td>" + pay.quantity + "</td>" +
                                    "</tr> ";
                    }
                    textBody += "</table> <br/><h3>Thank You</h3>";


                    //MailMessage mail = new MailMessage();
                    //SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    //mail.Subject = "Shopping Cart Order  ";
                    //mail.From = new MailAddress("*****@*****.**");
                    //mail.To.Add("*****@*****.**");
                    //mail.Subject = "Shopping Cart";
                    mail.Body = textBody;

                    mail.IsBodyHtml        = true;
                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "lash1234");
                    SmtpServer.EnableSsl   = true;
                    SmtpServer.Send(mail);
                }



                return(true);
            }


            catch (Exception ex)
            {
            }



            return(true);
        }
 public void AddMember(Member m)
 {
     _context.Members.Add(m);
     _context.SaveChanges();
 }
Beispiel #7
0
 public void AddCart(Cart c)
 {
     _context.Carts.Add(c);
     _context.SaveChanges();
 }
Beispiel #8
0
 public void AddOrderDetails(OrderDetails od)
 {
     _context.OrderDetails.Add(od);
     _context.SaveChanges();
 }
 public void AddOrder(Order o)
 {
     _context.Orders.Add(o);
     _context.SaveChanges();
 }