Exemplo n.º 1
0
        public async Task <ActionResult> Buy(BuyModel model)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri("https://cloud-sse.iexapis.com");
                    var response = await client.GetAsync($"/stable/stock/{model.Symbol}/quote?token=pk_f7b30f305a8c4aef8eaec49711a8344e");

                    response.EnsureSuccessStatusCode();

                    var stringResult = await response.Content.ReadAsStringAsync();

                    var    rawShare = JsonConvert.DeserializeObject <Bought>(stringResult);
                    string userId   = User.Claims.First(c => c.Type == "Id").Value;
                    var    user     = db.ApplicationUsers.Where(au => au.Id == userId).ToList();

                    double        total  = 0;
                    List <Bought> shares = db.Boughts.Where(s => s.AspNetUserId == userId).Where(s => s.IsOwned == true).ToList();
                    foreach (Bought item in shares)
                    {
                        total += (item.latestPrice * item.NumOfShare);
                    }

                    double cash = user[0].Fund - total;

                    double cost = rawShare.latestPrice * model.Share;

                    if (cash >= cost)
                    {
                        DateTime date = DateTime.Now;

                        Bought share = new Bought
                        {
                            TransactionType = "Buy",
                            DateAndTime     = date,
                            Symbol          = model.Symbol.ToUpper(),
                            companyName     = rawShare.companyName,
                            latestPrice     = rawShare.latestPrice,
                            NumOfShare      = model.Share,
                            IsOwned         = true,
                            AspNetUserId    = userId
                        };


                        db.Boughts.Add(share);
                        await db.SaveChangesAsync();

                        string message = "Bought";
                        return(Ok(new { message }));
                    }
                    string errorMessage = "Failed. Total cost exceeds your available cash.";
                    return(BadRequest(new { errorMessage }));
                }
                catch (HttpRequestException httpRequestException)
                {
                    return(BadRequest(new { httpRequestException.Message }));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Id = (int)id;

            Shoe = await _context.Shoe.FirstOrDefaultAsync(m => m.ShoeID == id);

            if (Shoe == null)
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user != null)
            {
                Bought QueryBought = new Bought {
                    Id = user.Id, ShoeID = Shoe.ShoeID
                };
                Bought bought = await _context.bought.FirstOrDefaultAsync(m => m.Id == QueryBought.Id && m.ShoeID == QueryBought.ShoeID);

                if (bought == null)
                {
                    return(RedirectToPage("../Shoes/Details/", new { id = id }));
                }
            }

            return(Page());
        }
        public async Task <IActionResult> PostBought(Bought item)
        {
            _context.Boughts.Add(item);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Exemplo n.º 4
0
        public void IsBoughtBy_UserIsCustomer_ReturnTrue()
        {
            var bought = new Bought();
            var result = bought.IsBoughtBy(new User {
                customer = true
            });

            Assert.IsTrue(result);
        }
Exemplo n.º 5
0
    public void InstanciateRandomlyTheObject(Bought toCreate)
    {
        Transform where = GetRandomPosition();
        if (where == null)
        {
            return;
        }
        GameObject gamo = Instantiate(toCreate.prefab, where.position, where.rotation);

        gamo.name = string.Format("#{0}({1})", toCreate.id, toCreate.who.UserName);
    }
        public async Task <IActionResult> PutBought(long id, Bought item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 7
0
        public IActionResult Buy(BuyViewModel model)
        {
            var buy = new Bought()
            {
                Name         = model.Name,
                Address      = model.Address,
                DeliveryType = model.DeliveryType,
                PhoneNumber  = model.PhoneNumber
            };

            this.context.Bought.Add(buy);
            this.context.SaveChanges();

            return(this.View());
        }
 public override void ObjectToInstanciateWhenItMust(Bought bought)
 {
     _toCreate.Add(bought);
 }
Exemplo n.º 9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Shoe = await _context.Shoe.FirstOrDefaultAsync(m => m.ShoeID == id);

            if (Shoe == null)
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user != null)
            {
                Bought QueryBought = new Bought {
                    Id = user.Id, ShoeID = Shoe.ShoeID
                };
                Bought bought = await _context.bought.FirstOrDefaultAsync(m => m.Id == QueryBought.Id && m.ShoeID == QueryBought.ShoeID);

                if (bought == null)
                {
                    Reviewable = false;
                }
                else
                {
                    Reviewable = true;
                }
            }

            try
            {
                Review = await _context.ReviewFinals.FirstOrDefaultAsync(m => m.ShoeID == id);

                if (Review == null)
                {
                    ReviewFinal NullReview = new ReviewFinal
                    {
                        ReviewID    = 0,
                        ShoeID      = (int)id,
                        ReviewName  = "No Reviews",
                        ReviewWords = "No Reviews"
                    };
                    Reviews = new List <ReviewFinal> {
                        NullReview
                    };
                }
                else
                {
                    var reviewQuery = from s in _context.ReviewFinals
                                      where s.ShoeID == Shoe.ShoeID
                                      select s;
                    Reviews = await reviewQuery.ToListAsync();
                }
            }
            catch
            {
                ReviewFinal NullReview = new ReviewFinal
                {
                    ReviewID    = 0,
                    ShoeID      = (int)id,
                    ReviewName  = "No Reviews",
                    ReviewWords = "No Reviews"
                };
                Reviews = new List <ReviewFinal> {
                    NullReview
                };
            }

            //if (User.IsInRole("Staff"))
            //{
            //    isAuth = true;
            //}
            return(Page());
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync(string stripeEmail, string stripeToken, int?id)
        {
            shoe = await _context.Shoe.FirstOrDefaultAsync(m => m.ShoeID == id);

            if (shoe == null)
            {
                return(NotFound());
            }

            var customers = new CustomerService();
            var charges   = new ChargeService();

            try {
                var customer = customers.Create(new CustomerCreateOptions
                {
                    Email  = stripeEmail,
                    Source = stripeToken
                });



                var charge = charges.Create(new ChargeCreateOptions
                {
                    Amount       = Convert.ToInt64(shoe.Price) * 100, //Need to change the amount to shopping cart page
                    Description  = shoe.Name,
                    Currency     = "sgd",
                    Customer     = customer.Id,
                    ReceiptEmail = stripeEmail // Send email receipt to customer
                });


                if (charge.Status == "succeeded")
                {
                    var user = await _userManager.GetUserAsync(User);

                    Bought QueryBought = new Bought {
                        Id = user.Id, ShoeID = shoe.ShoeID
                    };
                    var bought = await _context.bought.FirstOrDefaultAsync(m => m.Id == QueryBought.Id && m.ShoeID == QueryBought.ShoeID);

                    if (bought == null)
                    {
                        _context.bought.Add(QueryBought);
                        await _context.SaveChangesAsync();
                    }
                    string      receipturl = charge.ReceiptUrl;
                    string      subject    = "Cinderella Order Confirmation";
                    string      To         = charge.ReceiptEmail;
                    string      Body       = string.Format("Thanks for shopping with Cinderella \nTransaction No. :{0}\nAmount paid: ${1}\nYour order for {2} will be shipped to you shortly. Alternatively, you may view your e-receipt at {3}.", charge.Id, charge.Amount / 100, shoe.Name, receipturl);
                    MailMessage mail       = new MailMessage();
                    mail.To.Add(To);
                    mail.Subject    = subject;
                    mail.Body       = Body;
                    mail.IsBodyHtml = false;
                    mail.From       = new MailAddress("*****@*****.**");
                    SmtpClient smtp = new SmtpClient("smtp.gmail.com")
                    {
                        Port = 587,
                        UseDefaultCredentials = true,
                        EnableSsl             = true, //use SSL to secure connection
                        Credentials           = new System.Net.NetworkCredential("*****@*****.**", "Cinderella123!")
                    };
                    await smtp.SendMailAsync(mail);

                    if (charge.ReceiptEmail != user.Email)
                    {
                        string      nsubject = "Cinderella Order Confirmation";
                        string      nTo      = user.Email;
                        string      nBody    = string.Format("An order for {0} was made from your account\nIf this is not you, please contact us immediately", shoe.Name);
                        MailMessage nmail    = new MailMessage();
                        nmail.To.Add(nTo);
                        nmail.Subject    = nsubject;
                        nmail.Body       = nBody;
                        nmail.IsBodyHtml = false;
                        nmail.From       = new MailAddress("*****@*****.**");
                        await smtp.SendMailAsync(nmail);
                    }
                    TransactionLog log = new TransactionLog {
                        Id = user.Id, TransactionNumber = charge.Id, Time = DateTime.Now
                    };
                    _context.TransactionLogs.Add(log);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Success_Page"));
                }
                else
                {
                    //should make this display the error, like 'insufficient funds' or smth
                    return(RedirectToPage("./Fail_Transaction"));
                }
            }
            catch
            {
                return(RedirectToPage("./Fail_Transaction"));
            }
        }
Exemplo n.º 11
0
        public HttpResponseMessage Post([FromBody] Bought bought, int id)
        {
            try
            {
                string username = Thread.CurrentPrincipal.Identity.Name;
                using (DatabaseEntities entities = new DatabaseEntities())
                {
                    var    entity      = entities.Users.Where(e => e.Email.Equals(username)).FirstOrDefault();
                    var    IP          = entities.InProgresses.Where(e => e.IdItem == id).FirstOrDefault();
                    var    item        = entities.Items.Where(e => e.Id == id).FirstOrDefault();
                    var    userWhoSold = entities.Users.Where(e => e.Id == item.IdSeller).FirstOrDefault();
                    string emailBefore = "";
                    //  double pricebefore = 0;
                    try {
                        var priceBefore = entities.InProgresses.Where(e => e.IdItem == id).FirstOrDefault();

                        var userBefore = entities.Boughts.Where(e => e.IdItem == id && e.Price == priceBefore.ActualPrice).DefaultIfEmpty();
                        //  pricebefore = Convert.ToDouble(priceBefore.ActualPrice);
                        var UB = entities.Users.Where(e => e.Id == userBefore.FirstOrDefault().IdSeller).FirstOrDefault();
                        emailBefore = UB.Email.ToString();
                    }
                    catch (Exception edsg) { }



                    DateTime date = DateTime.Now;
                    bought.Date          = date;
                    bought.IdItem        = IP.IdItem;
                    bought.IdSeller      = entity.Id;
                    bought.Type          = IP.Type;
                    bought.NumberOfItems = Convert.ToInt32(bought.NumberOfItems);
                    bought.Price         = Convert.ToDouble(bought.Price);



                    // if (bought.Type.Equals("Licytacja") && !emailBefore.Equals(entity.Email))
                    // {
                    //      var EB = entities.Users.Where(e => e.Email.Equals(emailBefore)).FirstOrDefault();
                    //     EB.Money = EB.Money + pricebefore;
                    //      entity.Money = entity.Money - bought.Price;
                    //  }

                    if ((bought.Type.Equals("Licytacja") && (bought.Price != IP.PriceForOne)))
                    {
                        entity.Money = entity.Money - bought.Price;
                    }

                    if (bought.Type.Equals("Kup teraz"))
                    {
                        entity.Money = entity.Money - bought.Price;
                    }

                    if (bought.Type.Equals("Kup teraz") || (bought.Type.Equals("Licytacja") && (bought.Price == IP.PriceForOne)))
                    {
                        userWhoSold.Money = userWhoSold.Money + bought.Price;
                    }

                    entities.Boughts.Add(bought);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, bought);
                    if (bought.Type.Equals("Kup teraz"))
                    {
                        try {
                            System.Net.Mail.SmtpClient client = new SmtpClient();
                            // client.UseDefaultCredentials = false;
                            // client.Credentials new System.Net.NetworkCredential("yetju000", "uughns56", "yetju000-001-site1.htempurl.com");
                            client.Port                  = 587;
                            client.Host                  = "smtp.gmail.com";
                            client.EnableSsl             = true;
                            client.Timeout               = 10000;
                            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            client.UseDefaultCredentials = false;
                            client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "wchujdrogo");

                            MailMessage mm = new MailMessage("*****@*****.**", entity.Email, "Alledrogo - Zakupione przedmioty",
                                                             "Kupiłeś przedmiot[y] '" + item.Title + "'. Id aukcji:" + item.Id + "! Sztuk:" + bought.NumberOfItems + " Cena : " + bought.Price);
                            mm.BodyEncoding = UTF8Encoding.UTF8;
                            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                            client.Send(mm);


                            client                       = new SmtpClient();
                            client.Port                  = 587;
                            client.Host                  = "smtp.gmail.com";
                            client.EnableSsl             = true;
                            client.Timeout               = 10000;
                            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            client.UseDefaultCredentials = false;
                            client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "wchujdrogo");

                            mm = new MailMessage("*****@*****.**", userWhoSold.Email, "Alledrogo - Sprzedane przedmioty",
                                                 "Sprzedałeś przedmiot[y] '" + item.Title + "'. Id aukcji:" + item.Id + "! Sztuk:" + bought.NumberOfItems + " Cena : " + bought.Price);
                            mm.BodyEncoding = UTF8Encoding.UTF8;
                            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                            client.Send(mm);
                        }
                        catch (Exception exx)
                        {
                        }
                    }
                    else if (bought.Type.Equals("Licytacja"))
                    {
                        try
                        {
                            System.Net.Mail.SmtpClient client = new SmtpClient();
                            client.Port                  = 587;
                            client.Host                  = "smtp.gmail.com";
                            client.EnableSsl             = true;
                            client.Timeout               = 10000;
                            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            client.UseDefaultCredentials = false;
                            client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "wchujdrogo");

                            MailMessage mm = new MailMessage("*****@*****.**", emailBefore, "Alledrogo - Nowa cena aukcji którą licytowałeś",
                                                             "Została ustalona nowa cena przedmiot[y] '" + item.Title + "'. Id aukcji:" + item.Id + ". Nowa cena : " + bought.Price);
                            mm.BodyEncoding = UTF8Encoding.UTF8;
                            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                            client.Send(mm);

                            client.Port                  = 587;
                            client.Host                  = "smtp.gmail.com";
                            client.EnableSsl             = true;
                            client.Timeout               = 10000;
                            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                            client.UseDefaultCredentials = false;
                            client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "wchujdrogo");

                            mm = new MailMessage("*****@*****.**", userWhoSold.Email, "Alledrogo - Nowa cena twojej aukcji",
                                                 "Została ustalona nowa cena twojego przedmiot[y] '" + item.Title + "'. Id aukcji:" + item.Id + ". Nowa cena : " + bought.Price);
                            mm.BodyEncoding = UTF8Encoding.UTF8;
                            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                            client.Send(mm);
                        }
                        catch (Exception gdgd)
                        {
                        }
                    }
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
 public override void ObjectToInstanciateWhenItMust(Bought bought)
 {
     InstanciateRandomlyTheObject(bought);
 }
Exemplo n.º 13
0
 public abstract void ObjectToInstanciateWhenItMust(Bought bought);