Exemplo n.º 1
0
 public ActionResult Contact(HomeViewModels model)
 {
     if (ModelState.IsValid)
     {
         using (DigiStoreDBModelContainer db = new DigiStoreDBModelContainer())
         {
             //messing with this for the time being
             Review newReview = db.Reviews.Create();
             newReview.Id = db.Reviews.Count();
             if (model.ReviewText != null)
             {
                 newReview.ReviewText = model.ReviewText;
             }
             newReview.Rating       = 0;
             newReview.Date         = DateTime.Now;
             newReview.ReviewerName = "*****@*****.**";
             db.Reviews.Add(newReview);
             db.SaveChanges();
             ViewBag.Message = "Review Submitted! Thanks!";
             return(View());
         }
     }
     else
     {
         return(View(model));
     }
 }
Exemplo n.º 2
0
 public ActionResult StoreInventory(Item item, HttpPostedFileBase picture)
 {
     if (User.Identity.IsAuthenticated)
     {
         // Get our current user.
         User currentUser = ModelHelpers.GetCurrentUser(db);
         if (picture != null && picture.ContentLength > 0)
         {
             string path      = Server.MapPath("~/img/sub/pic" + (db.Items.Count() + 1) + "." + picture.FileName.Split('.').Last());
             string modelPath = "http://kt.digilife.me" + "/img/sub/pic" + (db.Items.Count() + 1) + "." + picture.FileName.Split('.').Last();
             picture.SaveAs(path);
             item.ImagePath = modelPath;
             ModelState.SetModelValue("ImagePath", new ValueProviderResult(modelPath, modelPath, System.Globalization.CultureInfo.CurrentCulture));
         }
         else
         {
             item.ImagePath = "http://kt.digilife.me" + "/img/help.png";
         }
         ModelState.Remove("ImagePath");
         if (ModelState.IsValid)
         {
             // Add the item to our current user.
             currentUser.Items.Add(item);
             // Save the changes to the DB.
             db.SaveChanges();
             // Return the user to the Store Inventory
             return(View("StoreInventory", currentUser));
         }
         return(View("StoreInventory", currentUser));
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
Exemplo n.º 3
0
        internal static void CreateUserPaymentMethodIfNotExisting(DigiStoreDBModelContainer db, User user)
        {
            User currentUser = ModelHelpers.GetCurrentUser(db);

            if (currentUser != null)
            {
                PaymentMethod payment = currentUser.PaymentMethods.FirstOrDefault();
                if (payment == null)
                {
                    payment = new PaymentMethod();
                    payment.AccountNumber = "";
                    payment.PaymentType   = "";
                    currentUser.PaymentMethods.Add(payment);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        internal static void CreateUserStoreIfNotExisting(DigiStoreDBModelContainer db, User user)
        {
            string[] DAYS_OF_THE_WEEK = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
            // If the user is not null, we continue
            if (user != null)
            {
                // If the user's store does not exist, we create it.
                if (user.Store == null)
                {
                    user.Store              = new Store();
                    user.Store.Address      = "";
                    user.Store.City         = "";
                    user.Store.Country      = "";
                    user.Store.Name         = user.UserName;
                    user.Store.PostalCode   = "";
                    user.Store.PhoneNumber  = "";
                    user.Store.StateProv    = "";
                    user.Store.StorePicture = "";
                }

                // If the user's store doesn't have hours, we add them now.
                // This is seperate for existing stores that don't have hours as of yet to receive store hours.
                if (user.Store.StoreHours.Count == 0)
                {
                    for (int i = user.Store.StoreHours.Count; i < 7; i++)
                    {
                        StoreHours storeHours = new StoreHours();
                        storeHours.StoreId      = user.Store.Id;
                        storeHours.DayOfTheWeek = DAYS_OF_THE_WEEK[i];
                        storeHours.StartTime    = new DateTime(2015, 1, 1, 1, 0, 0);
                        storeHours.EndTime      = new DateTime(2015, 1, 1, 1, 0, 0);
                        user.Store.StoreHours.Add(storeHours);
                    }
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 5
0
 public ActionResult SubmitReview(SubmitReviewViewModel model)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (ModelState.IsValid)
         {
             using (DigiStoreDBModelContainer db = new DigiStoreDBModelContainer())
             {
                 User   storeOwner = ModelHelpers.GetUserByEmail(db, model.StoreOwnerEmail);
                 Review newReview  = db.Reviews.Create();
                 if (model.ReviewText != null)
                 {
                     newReview.ReviewText = model.ReviewText;
                 }
                 if (model.ReviewRating != 0)
                 {
                     newReview.Rating = model.ReviewRating;
                 }
                 newReview.Date = DateTime.Now;
                 User existingUser = ModelHelpers.GetCurrentUser(db);
                 newReview.ReviewerName = existingUser.UserName;
                 storeOwner.Reviews.Add(newReview);
                 db.SaveChanges();
                 return(PartialView("_ReviewSuccess"));
             }
         }
         else
         {
             ViewBag.ReviewError = "Please enter 1-5 for the rating, and a review.";
             return(PartialView("_SubmitReview", model));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
Exemplo n.º 6
0
        public ActionResult PaymentWithPaypal()
        {
            //getting the apiContext as earlier
            APIContext apiContext = Configuration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];

                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist

                    //it is returned by the create function call of the payment class

                    // Creating a payment

                    // baseURL is the url on which paypal sendsback the data.

                    // So we have provided URL of this controller only

                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPayPal?";

                    //guid we are generating for storing the paymentID received in session

                    //after calling the create function and it is used in the payment execution

                    var guid = Convert.ToString((new Random()).Next(100000));

                    //CreatePayment function gives us the payment approval url

                    //on which payer is redirected for paypal acccount payment

                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //get links returned from paypal in response to Create function call

                    var links = createdPayment.links.GetEnumerator();

                    string paypalRedirectUrl = null;

                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;

                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }

                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);

                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This section is executed when we have received all the payments parameters

                    // from the previous call to the function Create

                    // Executing a payment

                    var guid = Request.Params["guid"];

                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                    if (executedPayment.state.ToLower() != "approved")
                    {
                        Session["cartError"] = "Your Payment Cannot be Processed. Please Try Again";
                        return(RedirectToAction("Cart", "Store"));
                    }
                }
            }
            catch (Exception ex)
            {
                Session["cartError"] = "Your Payment Cannot be Processed. Please Try Again";
                Logger.Log("Error" + ex.Message);
                return(RedirectToAction("Cart", "Store"));
            }

            // If we reach here, the payment was successful.
            // Creating a Order for the User
            User currentUser = ModelHelpers.GetCurrentUser(db);

            Models.Order order = new Models.Order();
            order.Id         = db.Orders.Count() + 8;
            order.Tax        = 0;
            order.TotalPrice = 0;
            foreach (nItem item in (List <nItem>)Session["cart"])
            {
                item.Ite.Quantity = item.Quantity;
                order.Items.Add(item.Ite);
                order.Tax        += item.Ite.Price * item.Ite.Quantity * 0.13M;
                order.TotalPrice += item.Ite.Price * item.Ite.Quantity;
                // Modifying the current Items' Quantities
                db.Items.Where(i => i.Id == item.Ite.Id).First().Quantity -= item.Quantity;
            }
            order.TotalPrice += order.Tax;
            currentUser.Orders.Add(order);

            // Lest we forgetti, Save the Spaghetti
            db.SaveChanges();
            // Empty the current cart.
            Session["cart"] = new List <nItem>();

            return(View("SuccessView", currentUser));
        }