Пример #1
0
 public string GetSellerID([FromForm] string email = null, [FromForm] string password = null, string name = null)
 {
     using SYLContext db = new SYLContext();
     if (email == null && password == null && name != null)
     {
         try
         {
             var value = db.Sellers.Where(x => x.SellerName.Equals(name)).FirstOrDefault().Id.ToString();
             return(value);
         }
         catch (Exception e)
         {
             return("Failed to get id from name." + e);
         }
     }
     else if (name == null && email != null && password != null)
     {
         try
         {
             var sellerID = db.Sellers.Where(x => x.Email.Equals(email) && x.Password.Equals(password)).FirstOrDefault().Id.ToString();
             return(sellerID);
         }
         catch (Exception e)
         {
             return("Failed to get id from email and password." + e);
         }
     }
     else
     {
         return("All parameters are null");
     }
 }
Пример #2
0
        // GETs all reviews for a specific seller.
        public List <Review> GetReviewList(string name)
        {
            using SYLContext db = new SYLContext();
            var reviews = db.Reviews.Where(x => x.SellerName.Equals(name)).ToList();

            return(reviews);
        }
Пример #3
0
 public List <string> GetAllSellers()
 {
     using (SYLContext db = new SYLContext())
     {
         return(db.Sellers.Select(x => x.SellerName).Distinct().ToList());
     }
 }
Пример #4
0
 public IActionResult addReview([FromForm] string username, [FromForm] int rating, [FromForm] string text, string name)
 {
     if (rating > 0 && rating <= 5)
     {
         try
         {
             using SYLContext db = new SYLContext();
             var review = new Review
             {
                 Username   = username,
                 Rating     = rating,
                 Text       = text,
                 SellerName = name
             };
             db.Reviews.Add(review);
             db.SaveChanges();
             return(Ok());
         }catch (SqlException sqlex) {
             _logger.LogInformation("SqlException happened. Probably primary key collision: " + sqlex);
             return(BadRequest());
         }catch (Exception e)
         {
             _logger.LogInformation("Exception happened: " + e);
             return(StatusCode(500));
         }
     }
     return(BadRequest());
 }
Пример #5
0
        public ReviewUnitTests()
        {
            var options = new DbContextOptionsBuilder <SYLContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            context = new SYLContext(options);
            //context.Database.EnsureCreated();

            Seed(context);
        }
Пример #6
0
        public void createSeller([FromForm] string sellerName, [FromForm] string adress, [FromForm] string pass, [FromForm] string email)
        {
            using SYLContext db = new SYLContext();
            var seller = new Seller
            {
                SellerName = sellerName,
                Adress     = adress,
                Password   = pass,
                Email      = email
            };

            db.Sellers.Add(seller);
            db.SaveChanges();
        }
Пример #7
0
 public void addProduct([FromForm] int shopID, [FromForm] double price, [FromForm] string name, [FromForm] int pID)
 {
     if (price > 0 && shopID >= 0 && pID >= 0)
     {
         using SYLContext db = new SYLContext();
         var product = new Product
         {
             ShopId        = shopID,
             Name          = name,
             Price         = price,
             ProductTypeId = pID
         };
         db.Products.Add(product);
         db.SaveChanges();
     }
 }
Пример #8
0
        public List <NOrder> GetOrders(int bID)
        {
            using SYLContext db = new SYLContext();
            var norders = (from s in db.Sellers
                           join o in db.Orders
                           on s.Id equals o.SellerId
                           where o.BuyerId == bID
                           select new NOrder
            {
                name = o.Name,
                time = o.Time.ToString(@"hh\:mm"),
                quantity = o.Quantity,
                adress = s.Adress
            }).ToList();

            return(norders);
        }
Пример #9
0
        public List <NProduct> Get()
        {
            using SYLContext db = new SYLContext();

            var products = (from p in db.Products
                            join s in db.Sellers
                            on p.ShopId equals s.Id
                            select new NProduct
            {
                name = p.Name,
                price = p.Price,
                sellerName = s.SellerName,
                adress = s.Adress
            }).ToList();


            return(products);
        }
Пример #10
0
        public void addOrder([FromForm] string name, [FromForm] string time, [FromForm] double quantity, [FromForm] int bID, [FromForm] int sID)
        {
            if (Regex.IsMatch(time, @"^[0-2]\d:[0-5]\d$") && quantity > 0 && bID >= 0 && sID >= 0)
            {
                using SYLContext db = new SYLContext();

                var order = new Order
                {
                    Name     = name,
                    Time     = TimeSpan.Parse(time),
                    Quantity = quantity,
                    BuyerId  = bID,
                    SellerId = sID
                };

                db.Orders.Add(order);
                db.SaveChanges();
            }
        }
Пример #11
0
 public ShopProcessor(SYLContext context)
 {
     this.context = context;
 }
Пример #12
0
 public UserProcessor(SYLContext context)
 {
     this.context = context;
 }
Пример #13
0
 public ReviewProcessor(SYLContext context)
 {
     this.context = context;
 }
Пример #14
0
        private void Seed(SYLContext context)
        {
            var users = new[]
            {
                new Users {
                    userEmail    = "*****@*****.**",
                    userId       = "TestUser-1",
                    userLastName = "Test",
                    userName     = "******",
                    userPassword = "******",
                    userType     = 1
                },
                new Users {
                    userEmail    = "*****@*****.**",
                    userId       = "TestUser-2",
                    userLastName = "Test",
                    userName     = "******",
                    userPassword = "******",
                    userType     = 0
                }
            };

            context.Users.AddRange(users);
            context.SaveChanges();

            var shops = new[]
            {
                new Shops
                {
                    shopAddress = "Test str. 1",
                    sellerId    = "TestUser-2",
                    shopId      = "TestShop-1",
                    shopName    = "Test1"
                },
                new Shops
                {
                    shopAddress = "Test str. 2",
                    sellerId    = "TestUser-2",
                    shopId      = "TestShop-2",
                    shopName    = "Test2"
                }
            };

            context.Shops.AddRange(shops);
            context.SaveChanges();

            var reviews = new[]
            {
                new Reviews
                {
                    reviewComment = "TestComment -1",
                    reviewId      = "Review-1",
                    reviewRating  = 1,
                    customerId    = "TestUser-1",
                    shopId        = "TestShop-1",
                    customerName  = "Test"
                },
                new Reviews
                {
                    reviewComment = "TestComment -2",
                    reviewId      = "Review-2",
                    reviewRating  = 3,
                    customerId    = "TestUser-1",
                    shopId        = "TestShop-2",
                    customerName  = "Test"
                },
                new Reviews
                {
                    reviewComment = "TestComment -3",
                    reviewId      = "Review-3",
                    reviewRating  = 5,
                    customerId    = "TestUser-2",
                    shopId        = "TestShop-2",
                    customerName  = "Test"
                }
            };

            context.Reviews.AddRange(reviews);
            context.SaveChanges();
        }