public ActionResult AddDeliveryLocation(int universities, string locationName, string address1, string address2, string city, string state, string zipCode, string phoneNumber, string DeliveryTime) { var location = new Location() { LocationName = locationName, BusinessName = locationName, FirstName = locationName, LastName = locationName, Address1 = address1, Address2 = address2, City = city, StateOrProvince = state, ZipCode = zipCode, PhoneNumber = phoneNumber, Country = "United States", CountryCode = "US" }; db.Locations.AddObject(location); var deliveryLocation = new University_Delivery() { UniversityId = universities, Location = location, DeliveryTime = DateTime.Parse(DeliveryTime) }; db.SaveChanges(); return RedirectToAction("ManageDeliveryHours"); }
public ActionResult CreateRestaurant(FormCollection values) { var location = new Location() { LocationName = values["Location_LocationName"], BusinessName = values["Location_LocationName"], Address1 = values["Location_Address1"], Address2 = values["Location_Address2"], City = values["Location_City"], StateOrProvince = values["Location_StateOrProvince"], ZipCode = values["Location_ZipCode"], FirstName = "", LastName = "", Country = "United States", CountryCode= CountryCodeType.US.ToString() }; db.Locations.AddObject(location); DateTime? hoursFrom=null, hoursTo=null, hours2From=null, hours2To=null; if(!string.IsNullOrEmpty(values["RestaurantHoursFrom"])) { hoursFrom = DateTime.Parse(values["RestaurantHoursFrom"]); } if(!string.IsNullOrEmpty(values["RestaurantHoursTo"])) { hoursTo = DateTime.Parse(values["RestaurantHoursTo"]); } if(!string.IsNullOrEmpty(values["RestaurantHours2From"])) { hours2From = DateTime.Parse(values["RestaurantHours2From"]); } if(!string.IsNullOrEmpty(values["RestaurantHours2To"])) { hours2To = DateTime.Parse(values["RestaurantHours2To"]); } var restaurant = new Restaurant() { RestaurantName = values["RestaurantName"], RestaurantShortDescription = values["RestaurantShortDescription"], RestaurantDetailedDescription = values["RestaurantDetailedDescription"], RestaurantHoursFrom = hoursFrom, RestaurantHoursTo = hoursTo, RestaurantHours2From = hours2From, RestaurantHours2To = hours2To, UniversityId = int.Parse(values["UniversityId"]), RestaurantStatusId = (int)Enum.Parse(typeof(RestaurantStatusLevel), values["RestaurantStatus"]), Location = location, RestaurantImageUrl = "", }; db.Restaurants.AddObject(restaurant); var bowl = new BentoBox() { BentoBoxName = "1-Entree Plate", BentoBoxDescription = "1-Entree Plate", BentoBoxTypeId = (int)BentoBoxType.OneEntreePlate, BentoBoxStatusId = (int)BentoBoxStatusLevel.Unavailable, Restaurant = restaurant, BentoBoxImageUrl = "", UnitPrice = 5.99m }; var twoEntree = new BentoBox() { BentoBoxName = "2-Entree Plate", BentoBoxDescription = "2-Entree Plate", BentoBoxTypeId = (int)BentoBoxType.TwoEntreePlate, BentoBoxStatusId = (int)BentoBoxStatusLevel.Unavailable, Restaurant = restaurant, BentoBoxImageUrl = "", UnitPrice = 6.99m }; var threeEntree = new BentoBox() { BentoBoxName = "3-Entree Plate", BentoBoxDescription = "3-Entree Plate", BentoBoxTypeId = (int)BentoBoxType.ThreeEntreePlate, BentoBoxStatusId = (int)BentoBoxStatusLevel.Unavailable, Restaurant = restaurant, BentoBoxImageUrl = "", UnitPrice = 7.99m }; var noodleAndRice = new BentoBox() { BentoBoxName = "Noodle and Rice", BentoBoxDescription = "Noodle and Rice", BentoBoxTypeId = (int)BentoBoxType.NoodleAndRice, BentoBoxStatusId = (int)BentoBoxStatusLevel.Unavailable, Restaurant = restaurant, BentoBoxImageUrl = "", UnitPrice = 6.99m }; db.BentoBoxes.AddObject(bowl); db.BentoBoxes.AddObject(twoEntree); db.BentoBoxes.AddObject(threeEntree); db.BentoBoxes.AddObject(noodleAndRice); db.SaveChanges(); return RedirectToAction("ManageRestaurants"); }
public ActionResult ManageUniversities(FormCollection values) { var location = new Location() { LocationName = values["LocationName"], BusinessName = values["LocationName"], FirstName = values["LocationName"], LastName = values["LocationName"], Address1 = values["Address1"], Address2 = values["Address2"], City = values["City"], StateOrProvince = values["State"], ZipCode = values["ZipCode"], PhoneNumber = values["PhoneNumber"], Country = "United States", CountryCode = "US" }; db.Locations.AddObject(location); var universityName = values["UniversityName"]; var university = new University() { Location = location, UniversityName = universityName }; db.Universities.AddObject(university); db.SaveChanges(); return View(new UniversitiesViewModel() { Universities = db.Universities }); }
/// <summary> /// Deprecated Method for adding a new object to the Locations EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToLocations(Location location) { base.AddObject("Locations", location); }
/// <summary> /// Create a new Location object. /// </summary> /// <param name="locationId">Initial value of the LocationId property.</param> /// <param name="locationName">Initial value of the LocationName property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="address1">Initial value of the Address1 property.</param> /// <param name="address2">Initial value of the Address2 property.</param> /// <param name="city">Initial value of the City property.</param> /// <param name="stateOrProvince">Initial value of the StateOrProvince property.</param> /// <param name="country">Initial value of the Country property.</param> /// <param name="countryCode">Initial value of the CountryCode property.</param> /// <param name="zipCode">Initial value of the ZipCode property.</param> public static Location CreateLocation(global::System.Int32 locationId, global::System.String locationName, global::System.String firstName, global::System.String lastName, global::System.String address1, global::System.String address2, global::System.String city, global::System.String stateOrProvince, global::System.String country, global::System.String countryCode, global::System.String zipCode) { Location location = new Location(); location.LocationId = locationId; location.LocationName = locationName; location.FirstName = firstName; location.LastName = lastName; location.Address1 = address1; location.Address2 = address2; location.City = city; location.StateOrProvince = stateOrProvince; location.Country = country; location.CountryCode = countryCode; location.ZipCode = zipCode; return location; }
public ActionResult MembershipDetails(FormCollection values) { var userId = MembershipHelper.GetUserIdByEmail(HttpContext.User.Identity.Name); var userDetails = db.UserDetails.Single(i=>i.UserId == userId); userDetails.FirstName = values["firstName"]; userDetails.LastName = values["lastName"]; userDetails.PhoneNumber = values["phoneNumber"]; userDetails.UniversityId = Convert.ToInt32(values["UniversityId"]); userDetails.UniversityDeliveryId = Convert.ToInt32(values["UniversityDeliveryId"]); if (userDetails.Location == null) { var location = new Location() { LocationName = values["LocationFirstName"] + values["LocationLastName"], FirstName = values["LocationFirstName"], LastName = values["LocationLastName"], Address1 = values["Address1"], Address2 = values["Address2"], City = values["City"], StateOrProvince = values["State"], ZipCode = values["ZipCode"], CountryCode = "US", Country = "United States" }; db.Locations.AddObject(location); db.SaveChanges(); userDetails.LocationId = location.LocationId; } else { userDetails.Location.FirstName = values["LocationFirstName"]; userDetails.Location.LastName = values["LocationLastName"]; userDetails.Location.Address1 = values["Address1"]; userDetails.Location.Address2 = values["Address2"]; userDetails.Location.City = values["City"]; userDetails.Location.StateOrProvince = values["State"]; userDetails.Location.ZipCode = values["ZipCode"]; } try { db.UserDetails.ApplyCurrentValues(userDetails); db.SaveChanges(); ViewBag.UpdateStatus = "Successful"; } catch (Exception ex) { ViewBag.UpdateStatus = ex.Message; } var universities = db.Universities .Select(i => new { Text = i.UniversityName, Value = i.UniversityId }).AsEnumerable() .Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString(), Selected = (userDetails.UniversityId.HasValue ? userDetails.UniversityId.Value == x.Value : false)}).ToList(); var deliveryLocations = db.University_Delivery .Where(i => userDetails.UniversityId.HasValue ? i.UniversityId == userDetails.UniversityId : false) .Select(i => new { i.UniversityDeliveryId, i.Location.BusinessName, i.DeliveryTime }).AsEnumerable() .Select(i => new SelectListItem { Text = i.BusinessName + " " + i.DeliveryTime.ToString("hh:mm tt"), Value = i.UniversityDeliveryId.ToString(), Selected = (userDetails.UniversityDeliveryId.HasValue? i.UniversityDeliveryId== userDetails.UniversityDeliveryId.Value : false )}).ToList(); var detailModel = new UserDetailsViewModel { FirstName = userDetails.FirstName, LastName = userDetails.LastName, PhoneNumber = userDetails.PhoneNumber, LocationFirstName = userDetails.Location != null ? userDetails.Location.FirstName : "", LocationLastName = userDetails.Location != null ? userDetails.Location.LastName : "", Address1 = userDetails.Location != null ? userDetails.Location.Address1 : "", Address2 = userDetails.Location != null ? userDetails.Location.Address2 : "", City = userDetails.Location != null ? userDetails.Location.City : "", State = userDetails.Location != null ? userDetails.Location.StateOrProvince : "", ZipCode = userDetails.Location != null ? userDetails.Location.ZipCode : "", Universities = universities, States = MyLunchBox.Models.StatesRepository.Instance.StatesListWithSelectedItem(userDetails.Location != null ? userDetails.Location.StateOrProvince : ""), DeliveryLocations = deliveryLocations, UniversityId = userDetails.UniversityId.HasValue ? userDetails.UniversityId.Value : -1, UniversityDeliveryId = userDetails.UniversityDeliveryId.HasValue ? userDetails.UniversityDeliveryId.Value : -1 }; return View(detailModel); }
public void OnPaymentComplete( PaymentType paymentType, PaymentStatusLevel paymentStatus, BillingInfo billingInfo, DeliveryInfo deliveryInfo, Order order) { if ( paymentType == PaymentType.CreditCard && paymentStatus == PaymentStatusLevel.WaitingForPayment) { // payment failed, we won't record it in db order.PaymentStatus = paymentStatus.ToString(); } else { var cart = ShoppingCartHelper.GetCart(HttpContext); order.PaymentStatus = paymentStatus.ToString(); order.TxnId = order.TxnId; order.OrderStatusId = (int)OrderStatusLevel.Processing; order.PaymentNote = paymentType.ToString() ; order.OrderReceivedAt = DateTime.Now; db.Orders.AddObject(order); db.SaveChanges(); foreach (var cartItem in cart.ShoppingCartItems) { order.OrderItems.Add(new OrderItem() { OrderId = order.OrderId, ItemId = cartItem.ItemId, ItemTypeId = cartItem.ItemTypeId, LineItemCost = cartItem.LineItemCost, Quantity = cartItem.Quantity }); } db.SaveChanges(); // save payer details var payer = (MyLunchBoxMembershipUser)(new MyLunchBoxMembershipProvider().GetUser(User.Identity.Name, true)); var userDetails = db.UserDetails.Single(i => i.UserId == order.UserId); userDetails.FirstName = order.ReceiverFirstName; userDetails.LastName = order.ReceiverLastName; userDetails.UniversityId = LocationHelper.GetSelectedUniversityId(HttpContext); userDetails.UniversityDeliveryId = LocationHelper.GetDeliveryLocationId(HttpContext); if (billingInfo != null) { if (userDetails.Location == null) { var location = new Location() { LocationName = billingInfo.BillingAddress1, FirstName = billingInfo.BillingFirstName, LastName = billingInfo.BillingLastName, Address1 = billingInfo.BillingAddress1, Address2 = billingInfo.BillingAddress2, City = billingInfo.City, StateOrProvince = billingInfo.State, ZipCode = billingInfo.ZipCode, CountryCode = billingInfo.CountryCode.ToString(), Country = "United States" }; db.Locations.AddObject(location); db.SaveChanges(); userDetails.LocationId = location.LocationId; } else { userDetails.Location.FirstName = billingInfo.BillingFirstName; userDetails.Location.LastName = billingInfo.BillingLastName; userDetails.Location.Address1 = billingInfo.BillingAddress1; userDetails.Location.Address2 = billingInfo.BillingAddress2; userDetails.Location.City = billingInfo.City; userDetails.Location.StateOrProvince = billingInfo.State; userDetails.Location.ZipCode = billingInfo.ZipCode; } } db.UserDetails.ApplyCurrentValues(userDetails); db.SaveChanges(); //process reward if (order.rewardPoints > 0) { var reward = new Reward() { Amount = -order.rewardPoints, RewardTypeId = (int)RewardType.Order, OrderId = order.OrderId, RewardCreatedAt = DateTime.Now, UserId = MembershipHelper.GetUserIdByEmail(payer.UserName), RewardDescription = "Consume reward points" }; db.Rewards.AddObject(reward); } if(order.OrderItems.Count(i=>i.ItemTypeId == (int)ItemType.MembershipCard) > 0) { var rewardCards = order.OrderItems.Where(i=>i.ItemTypeId == (int)ItemType.MembershipCard); var totalPoints = 0.0m; foreach( var rewardCard in rewardCards) { var card = db.RewardCards.Single(i=>i.RewardCardId == rewardCard.ItemId); totalPoints += card.RewardPoints * rewardCard.Quantity; } var reward = new Reward() { Amount = totalPoints, RewardTypeId = (int)RewardType.RewardCard, OrderId = order.OrderId, Txn = order.TxnId, RewardCreatedAt = DateTime.Now, UserId = MembershipHelper.GetUserIdByEmail(payer.UserName), RewardDescription = "Reward Card Redeemed" }; db.Rewards.AddObject(reward); } db.SaveChanges(); var oss = new OrderStatusService(); oss.SendOrderConfirmationMail(order.OrderId); // empty shopping cart ShoppingCartHelper.EmptyCart(HttpContext); } }