public IHttpActionResult PutBooking(int id, Booking booking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != booking.ID) { return(BadRequest()); } db.Entry(booking).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Putmovies(int id, visning movies) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movies.id) { return(BadRequest()); } db.Entry(movies).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!moviesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public object InsertMember(Register Reg) { try { FilmenRegistration MemberLogin = new FilmenRegistration(); if (MemberLogin.Id == 0) { MemberLogin.FirstName = Reg.FirstName; MemberLogin.LastName = Reg.LastName; MemberLogin.City = Reg.City; MemberLogin.Email = Reg.Email; MemberLogin.Password = Reg.Password; MemberLogin.SocialSecurityNR = Reg.SocialSecurityNR; DB.FilmenRegistrations.Add(MemberLogin); DB.SaveChanges(); return(new Response { Status = "Success", Message = "SuccessFully Saved." }); } } catch (Exception) { throw; } return(new Response { Status = "Error", Message = "Invalid Data." }); }
public Guid PutTrip(string id = "", string origin = "", string destination = "", string departureTime = "", string arrivalTime = "", string saleTotal = "", string stops = "" , string number = "", string carrier = "", string adultCount = "") { Cart ticket = new Cart(); ticket.origin = origin; ticket.TicketId = id; ticket.destination = destination; ticket.departureTime = DateTime.Parse(departureTime); ticket.arrivalTime = DateTime.Parse(arrivalTime); ticket.saleTotal = saleTotal; ticket.stops = stops; ticket.carrier = carrier; ticket.number = number; ticket.adultCount = adultCount; ticket.Id = Guid.NewGuid(); //TODO: save selected trip details to cart using (MemberEntities1 entities = new MemberEntities1()) { entities.Carts.Add(ticket); entities.SaveChanges(); } return(ticket.Id); }
public async Task <ActionResult> Index(CheckoutModel model2) { using (MemberEntities1 entities = new MemberEntities1()) { //int orderId = int.Parse(Request.Cookies["OrderID"].Value); var cart = entities.Carts.Single(x => x.Id == model2.id); Order o = new Order(); cart.Orders.Add(o); if (ModelState.IsValid) { bool addressValidationSuccessful = true; bool validateAddress = false; string smartyStreetsAuthId = ConfigurationManager.AppSettings["SmartyStreets.AuthId"]; string smartyStreetsAuthToken = ConfigurationManager.AppSettings["SmartyStreets.AuthToken"]; Rentler.SmartyStreets.SmartyStreetsClient client = new Rentler.SmartyStreets.SmartyStreetsClient(smartyStreetsAuthId, smartyStreetsAuthToken); var addresses = await client.GetStreetAddressAsync(model2.BillingStreet1, null, model2.BillingStreet2, model2.BillingCity, model2.BillingState, model2.BillingPostalCode); if (addresses.Count() == 0) { ModelState.AddModelError("BillingStreet1", "Could not find exact or similiar address"); addressValidationSuccessful = false; } else { if (!string.IsNullOrEmpty(model2.BillingStreet1) && addresses.First().delivery_line_1 != model2.BillingStreet1) { ModelState.AddModelError("BillingStreet1", string.Format("Suggested Address: {0}", addresses.First().delivery_line_1)); addressValidationSuccessful = false; } if (!string.IsNullOrEmpty(model2.BillingStreet2) && addresses.First().delivery_line_2 != model2.BillingStreet2) { ModelState.AddModelError("BillingStreet2", string.Format("Suggested Address: {0}", addresses.First().delivery_line_2)); addressValidationSuccessful = false; } if (!string.IsNullOrEmpty(model2.BillingCity) && addresses.First().components.city_name != model2.BillingCity) { ModelState.AddModelError("BillingCity", string.Format("Suggested Address: {0}", addresses.First().components.city_name)); addressValidationSuccessful = false; } if (!string.IsNullOrEmpty(model2.BillingPostalCode) && addresses.First().components.zipcode != model2.BillingPostalCode) { ModelState.AddModelError("BillingPostalCode", string.Format("Suggested Address: {0}", addresses.First().components.zipcode)); addressValidationSuccessful = false; } if (!string.IsNullOrEmpty(model2.BillingState) && addresses.First().components.state_abbreviation != model2.BillingState) { ModelState.AddModelError("BillingState", string.Format("Suggested Address: {0}", addresses.First().components.state_abbreviation)); addressValidationSuccessful = false; } } if (addressValidationSuccessful || !validateAddress) { //TODO: Validate the credit card - if it errors out, add a model error and display it to the user string publicKey = ConfigurationManager.AppSettings["Braintree.PublicKey"]; string privateKey = ConfigurationManager.AppSettings["Braintree.PrivateKey"]; string environment = ConfigurationManager.AppSettings["Braintree.Environment"]; string merchantId = ConfigurationManager.AppSettings["Braintree.MerchantId"]; Braintree.BraintreeGateway braintree = new Braintree.BraintreeGateway(environment, merchantId, publicKey, privateKey); int userId = -1; if (string.IsNullOrEmpty(User.Identity.Name)) { userId = 34; var customer = braintree.Customer.Find(userId.ToString()); Braintree.CustomerRequest request = new Braintree.CustomerRequest(); request.CreditCard = new Braintree.CreditCardRequest(); request.CreditCard.Number = model2.CreditCardNumber; request.CreditCard.CardholderName = model2.CreditCardName; request.CreditCard.ExpirationMonth = (model2.CreditCardExpirationMonth).ToString().PadLeft(2, '0'); request.CreditCard.ExpirationYear = model2.CreditCardExpirationYear.ToString(); var customerResult = braintree.Customer.Update(userId.ToString(), request); Braintree.TransactionRequest sale = new Braintree.TransactionRequest(); sale.Amount = decimal.Parse(cart.saleTotal.Replace("USD", string.Empty)); sale.CustomerId = customerResult.Target.Id; sale.PaymentMethodToken = customerResult.Target.DefaultPaymentMethod.Token; braintree.Transaction.Sale(sale); o.FirstName = model2.FirstName; o.LastName = model2.LastName; o.EmailAddress = model2.EmailAddress; o.PhoneNumber = model2.PhoneNumber; o.BillingCity = model2.BillingCity; o.BillingPostalCode = model2.BillingPostalCode; o.BillingReceipient = model2.BillingReceipient; o.BillingStreet1 = model2.BillingStreet1; o.BillingStreet2 = model2.BillingStreet2; o.BillingState = model2.BillingState; o.DateCreated = DateTime.UtcNow; o.DateLastModified = DateTime.UtcNow; entities.SaveChanges(); return(RedirectToAction("Index", "Receipt", new { id = o.OrderId })); } else { using (MemberEntities1 e = new MemberEntities1()) { userId = e.CustomerLists.Single(x => x.EmailAddress == User.Identity.Name).ID; } var customer = braintree.Customer.Find(userId.ToString()); Braintree.CustomerRequest request = new Braintree.CustomerRequest(); request.CreditCard = new Braintree.CreditCardRequest(); request.CreditCard.Number = model2.CreditCardNumber; request.CreditCard.CardholderName = model2.CreditCardName; request.CreditCard.ExpirationMonth = (model2.CreditCardExpirationMonth).ToString().PadLeft(2, '0'); request.CreditCard.ExpirationYear = model2.CreditCardExpirationYear.ToString(); var customerResult = braintree.Customer.Update(userId.ToString(), request); Braintree.TransactionRequest sale = new Braintree.TransactionRequest(); sale.Amount = decimal.Parse(cart.saleTotal.Replace("USD", string.Empty)); sale.CustomerId = customerResult.Target.Id; sale.PaymentMethodToken = customerResult.Target.DefaultPaymentMethod.Token; braintree.Transaction.Sale(sale); o.FirstName = model2.FirstName; o.LastName = model2.LastName; o.EmailAddress = model2.EmailAddress; o.PhoneNumber = model2.PhoneNumber; o.BillingCity = model2.BillingCity; o.BillingPostalCode = model2.BillingPostalCode; o.BillingReceipient = model2.BillingReceipient; o.BillingStreet1 = model2.BillingStreet1; o.BillingStreet2 = model2.BillingStreet2; o.BillingState = model2.BillingState; o.DateCreated = DateTime.UtcNow; o.DateLastModified = DateTime.UtcNow; entities.SaveChanges(); return(RedirectToAction("Index", "Receipt", new { id = o.OrderId })); } } } } return(View(model2)); }