public IActionResult MyPackage() { CustomerCard card = _cardService.GetCurrentUserCard(_userManager.GetUserId(HttpContext.User)); Package package = _packageService.GetById(card.Package.Id); SetBox SetBox = _sbService.GetById(card.SetBox.Id); Customer cus = _cusService.GetByUser(_userManager.GetUserId(HttpContext.User)); DateTime expire = _cpService.GetExpirationTime(cus.Id); CustomerPackage cp = _cpService.GetByCardId(card.Id); string status = UpdatePakageStatus(cp, expire); MyPackageViewModel model = new MyPackageViewModel { MyPackage = new PackageDetailViewModel { PackageName = package.PackageName, NoOfChannels = package.NoOfChannels, Charges = package.Charges, ImageUrl = package.ImageUrl }, MySetBox = new SetBoxDetailModel { Name = SetBox.Name, Specification = SetBox.Specification, Price = SetBox.Price, ImageUrl = SetBox.ImageUrl }, GetExpiration = expire, State = status }; return(View(model)); }
public async Task <int> PullCard(Card card) { var customerCard = await _customerCards.Queryable().Include(x => x.StripeCard) .Where(x => x.Id == card.Id).FirstOrDefaultAsync(); if (customerCard == null) { customerCard = new CustomerCard() { Id = card.Id, ObjectState = ObjectState.Added, StripeCard = new StripeCard() { Id = card.Id, ObjectState = ObjectState.Added } }; } else { customerCard.StripeCard.ObjectState = ObjectState.Modified; customerCard.ObjectState = ObjectState.Modified; } customerCard.CustomerId = card.CustomerId; customerCard.Id = card.Id; customerCard.StripeCard.InjectFrom(card); return(_customerCards.InsertOrUpdateGraph(customerCard, true)); }
public static string ImportCards(StationsDbContext context, string xmlString) { XmlSerializer serializer = new XmlSerializer(typeof(CardDto[]), new XmlRootAttribute("Cards")); CardDto[] cardDtos = (CardDto[])serializer.Deserialize(new StringReader(xmlString)); StringBuilder sb = new StringBuilder(); List <CustomerCard> cards = new List <CustomerCard>(); foreach (CardDto dto in cardDtos) { if (!IsValid(dto)) { sb.AppendLine(FailureMessage); continue; } CardType cardType = Enum.TryParse <CardType>(dto.CardType, out var card) ? card : CardType.Normal; CustomerCard customerCard = new CustomerCard { Name = dto.Name, Type = cardType, Age = dto.Age }; cards.Add(customerCard); sb.AppendLine(string.Format(SuccessMessage, customerCard.Name)); } context.Cards.AddRange(cards); context.SaveChanges(); return(sb.ToString().Trim()); }
public static string ImportCards(StationsDbContext context, string xmlString) { var serializer = new XmlSerializer(typeof(ImportDto.CardDto[]), new XmlRootAttribute("Cards")); ImportDto.CardDto[] deserializedCards = (ImportDto.CardDto[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); StringBuilder sb = new StringBuilder(); List <CustomerCard> cards = new List <CustomerCard>(); foreach (var cardDto in deserializedCards) { if (!IsValid(cardDto)) { sb.AppendLine(FailureMessage); continue; } CustomerCard card = new CustomerCard() { Name = cardDto.Name, Age = cardDto.Age, Type = cardDto.CardType, }; cards.Add(card); sb.AppendLine(string.Format(SuccessMessage, cardDto.Name)); } context.AddRange(cards); context.SaveChanges(); return(sb.ToString().Trim()); }
public async Task <IActionResult> PutCustomerCard(int id, CustomerCard customerCard) { if (id != customerCard.Id) { return(BadRequest()); } _context.Entry(customerCard).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerCardExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <CustomerCard> > PostCustomerCard(CustomerCard customerCard) { _context.CustomerCards.Add(customerCard); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCustomerCard", new { id = customerCard.Id }, customerCard)); }
public static string ImportCards(StationsDbContext context, string xmlString) { var cards = new List <CustomerCard>(); var result = new StringBuilder(); var serializer = new XmlSerializer(typeof(CustomerCardDto[]), new XmlRootAttribute("Cards")); var objCards = (CustomerCardDto[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); foreach (var objCard in objCards) { if (!IsValid(objCard)) { result.AppendLine(FailureMessage); continue; } var type = Enum.Parse <CardType>(objCard.CardType); var card = new CustomerCard { Name = objCard.Name, Age = objCard.Age, Type = type }; cards.Add(card); result.AppendLine(string.Format(SuccessMessage, card.Name)); } context.Cards.AddRange(cards); context.SaveChanges(); return(result.ToString()); }
public static string ImportCards(StationsDbContext context, string xmlString) { XmlSerializer serializer = new XmlSerializer(typeof(CardImportDto[]), new XmlRootAttribute("Cards")); var cards = (CardImportDto[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); List <CustomerCard> validCards = new List <CustomerCard>(); StringBuilder sb = new StringBuilder(); foreach (var card in cards) { if (!IsValid(card)) { sb.AppendLine(FailureMessage); continue; } CardType type = CardType.Normal; if (card.CardType != null) { type = Enum.Parse <CardType>(card.CardType); } CustomerCard customerCard = new CustomerCard(card.Name, card.Age, type); validCards.Add(customerCard); sb.AppendLine(string.Format(SuccessMessage, card.Name)); } context.Cards.AddRange(validCards); context.SaveChanges(); return(sb.ToString().TrimEnd()); }
public async Task CreateAsync_Success() { CustomerRequest customerRequest = BuildCustomerCreateRequest(); var customerClient = new CustomerClient(); Customer customer = await customerClient.CreateAsync(customerRequest); await Task.Delay(1000); try { CustomerCardCreateRequest cardRequest = await BuildCardCreateRequestAsync(); CustomerCard card = await customerClient.CreateCardAsync(customer.Id, cardRequest); var request = new CardTokenRequest { CustomerId = customer.Id, CardId = card.Id, SecurityCode = "123", }; CardToken cardToken = await client.CreateAsync(request); Assert.NotNull(cardToken); Assert.NotNull(cardToken.Id); } finally { customerClient.Delete(customer.Id); } }
public static string ImportCards(StationsDbContext context, string xmlString) { StringBuilder sb = new StringBuilder(); var serializer = new XmlSerializer(typeof(CustomerCard), new XmlRootAttribute("cards")); var deserializedCards = (CustomerCard[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); List <CustomerCard> cards = new List <CustomerCard>(); foreach (var card in deserializedCards) { if (!IsValid(card)) { sb.AppendLine(FailureMessage); continue; } var cardType = Enum.TryParse <CardType>(card.Type.ToString(), out var card1) ? card1 : CardType.Normal; var customCard = new CustomerCard() { Name = card.Name, Type = cardType, Age = card.Age }; cards.Add(customCard); sb.AppendLine(string.Format(SuccessMessage, customCard.Name)); } context.Cards.AddRange(cards); context.SaveChanges(); return(sb.ToString()); }
public void Get_Success() { CustomerRequest customerRequest = BuildCustomerCreateRequest(); var customerClient = new CustomerClient(); Customer customer = customerClient.Create(customerRequest); Thread.Sleep(1000); try { CustomerCardCreateRequest cardRequest = BuildCardCreateRequest(); CustomerCard card = customerClient.CreateCard(customer.Id, cardRequest); var request = new CardTokenRequest { CustomerId = customer.Id, CardId = card.Id, SecurityCode = "123", }; CardToken createdCartToken = client.Create(request); Thread.Sleep(1000); CardToken cardToken = client.Get(createdCartToken.Id); Assert.NotNull(cardToken); Assert.Equal(createdCartToken.Id, cardToken.Id); } finally { customerClient.Delete(customer.Id); } }
public static string ImportCards(StationsDbContext context, string xmlString) { var sb = new StringBuilder(); var serializer = new XmlSerializer(typeof(CardDto[]), new XmlRootAttribute("Cards")); var deserializedCard = (CardDto[])serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); var validCards = new List <CustomerCard>(); foreach (var dto in deserializedCard) { if (!IsValid(dto)) { sb.AppendLine(FailureMessage); continue; } var cardType = Enum.TryParse <CardType>(dto.CardType, out var cardT) ? cardT : CardType.Normal; var card = new CustomerCard { Name = dto.Name, Type = cardType, Age = dto.Age }; validCards.Add(card); sb.AppendLine(String.Format(SuccessMessage, $"{card.Name}")); } context.Cards.AddRange(validCards); context.SaveChanges(); return(sb.ToString()); }
public ActionResult Index() { try { var customerId = CustomerId(); if (customerId == 0) { return(Redirect("/Me/JoinUs/Index")); } ViewData["CustomerName"] = CustomerName(); ViewData["WeixinUser"] = WeiXinUser(); LogManager.GetLogger().Info("customerId:" + customerId); ViewData["CustoemrBase"] = CustomerBase.FindById(customerId); var customerCards = CustomerCard.FindByList(customerId: customerId); ViewData["CustomerCards"] = customerCards; var orderBases = OrderBaseInfo.FindByList(customerId: customerId); ViewData["OrderBases"] = orderBases; ViewData["CustomerBases"] = CustomerBase.FindByList(parentId: customerId); } catch (Exception ex) { LogManager.GetLogger().Error(ex); } return(View()); }
public async Task <IActionResult> Create([FromBody] string CustomerCard) { List <CustomerCardRowAddDto> customerCardRowAddDtos = JsonConvert.DeserializeObject <List <CustomerCardRowAddDto> >(CustomerCard); CustomerCardAddDto customerCardAddDto = new CustomerCardAddDto(); customerCardAddDto.CustomerCardRowAddDto = customerCardRowAddDtos; User user = await _userManager.FindById(Convert.ToInt32(customerCardRowAddDtos[0].ProductManagerName)); customerCardAddDto.CustomerCardName = customerCardRowAddDtos[0].CustomerCardName; customerCardAddDto.ProductManagerName = user.Name; Customer customer = _customerManager.Find(x => x.CustomerId == Convert.ToInt32(customerCardRowAddDtos[0].CustomerName)); customerCardAddDto.CustomerName = customer.CustomerName; customerCardAddDto.FinishedDate = DateTime.Now.AddDays(7); if (ModelState.IsValid) { List <CustomerCardRow> customerCardRow = _mapper.Map <List <CustomerCardRow> >(customerCardRowAddDtos); CustomerCard customerCardAdd = _mapper.Map <CustomerCard>(customerCardAddDto); customerCardRow.ForEach(x => x.CustomerCardId = customerCardAdd.CustomerCardId); customerCardAdd.CustomerCardRow = customerCardRow; customerCardAdd.CustomerId = customer.CustomerId; customerCardAdd.CostOfCardTime = customerCardAdd.CustomerCardRow.Count * 4; await _customerCardManager.AddAsync(customerCardAdd); return(RedirectToAction("Index", "Home")); } else { return(View(CustomerCard)); } }
public static string ImportCards(StationsDbContext context, string xmlString) { var serializer = new XmlSerializer(typeof(CardDto[]), new XmlRootAttribute("Cards")); var cardsFromXml = (CardDto[])serializer.Deserialize(new StringReader(xmlString)); var sb = new StringBuilder(); var resultCards = new List <CustomerCard>(); foreach (var cardDto in cardsFromXml) { if (!IsValid(cardDto)) { sb.AppendLine(FailureMessage); continue; } var type = Enum.Parse <CardType>(cardDto.CardType); var currentCard = new CustomerCard { Name = cardDto.Name, Age = cardDto.Age, Type = type }; resultCards.Add(currentCard); sb.AppendLine(string.Format(SuccessMessage, currentCard.Name)); } context.Cards.AddRange(resultCards); context.SaveChanges(); return(sb.ToString().Trim()); }
public async Task <IActionResult> Delete(int id) { CustomerCard deletedCustomer = await _customerCardManager.FindById(id); await _customerCardManager.RemoveAsync(deletedCustomer); return(RedirectToAction("Index", "Home")); }
public FormCutomerCard(List <string> i_VehicleInfo, string i_VehicleType, CustomerCard i_CustomerToTreat, Garage i_GarageManager) { r_GarageManager = i_GarageManager; InitializeComponent(); InitializeCustomerDetails(i_VehicleInfo, i_VehicleType); m_CustomerToTreat = i_CustomerToTreat; this.buttonCreateCustomerCard.Click += ButtonCreateCustomerCard_Click; }
public static bool ShouldShowRegistrationForm(this CustomerCard contest) { // Show registration form if contest password is required var showRegistrationForm = contest.HasCustomerCardPassword; // Show registration form if contest is official and questions should be asked return(showRegistrationForm); }
public IActionResult Update(CustomerCard customerCard) { var result = _customerCardService.Update(customerCard); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Add(CustomerCard customerCreditCard) { var result = _customerCardService.Add(customerCreditCard); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
private void newCustomerActions() { Vehicle vehicleToCreate = GarageLogic.VehicleCreator.Create(textBoxLicencePlate.Text, ComboBoxVehicleType.Text); m_CustomerToTreat = new CustomerCard(vehicleToCreate); List <string> vehicleInfo = m_CustomerToTreat.Vehicle.GetDataNames(); FormCutomerCard formCutomerCard = new FormCutomerCard(vehicleInfo, ComboBoxVehicleType.Text, m_CustomerToTreat, r_GarageManager); formCutomerCard.ShowDialog(); }
public static void AddTickets(List <TicketImportDto> ticketDtos) { using (var context = new StationsContext()) { foreach (var ticketDto in ticketDtos) { // Validate input Trip trip = context.Trips .FirstOrDefault(t => t.OriginStation.Name == ticketDto.OriginStation && t.DestinationStation.Name == ticketDto.DestinationStation && t.DepartureTime == ticketDto.DepartureTime); CustomerCard card = context.CustomerCards .FirstOrDefault(c => c.Name == ticketDto.CardName); SeatingClass seatingClass = context.SeatingClasses .FirstOrDefault(c => c.Abbreviation == ticketDto.Seat.Substring(0, 2)); if (trip == null || card == null || seatingClass == null) { Console.WriteLine("Invalid data format."); continue; } // Validate train seats var trainSeats = context.TrainSeats .FirstOrDefault(ts => ts.TrainId == trip.TrainId && ts.SeatingClassId == seatingClass.Id); if (trainSeats == null) { Console.WriteLine("Invalid data format."); continue; } // Validate seat number int seatNumber = int.Parse(ticketDto.Seat.Substring(2)); if (seatNumber < 0 || seatNumber > trainSeats.Quantity) { Console.WriteLine("Invalid data format."); continue; } // Add ticket to DB Ticket ticket = new Ticket { TripId = trip.Id, Price = ticketDto.Price, SeatingPlace = ticketDto.Seat, PersonalCardId = card.Id }; context.Tickets.Add(ticket); context.SaveChanges(); // Success Notification Console.WriteLine($"Ticket from {ticketDto.OriginStation} to {ticketDto.DestinationStation} departing at {ticketDto.DepartureTime} imported."); } } }
public FormVehicleStates(string i_ActionToDo, CustomerCard i_CustomerToTreat, Garage i_GarageManager) { InitializeComponent(); m_ActionToDo = i_ActionToDo; r_GarageManager = i_GarageManager; CustomerToTreat = i_CustomerToTreat; this.buttonDoAction.Text = i_ActionToDo; this.LabelChooseOption.Text = "Choose the state you want to change to:"; this.buttonDoAction.Click += ButtonDoAction_Click; initializeVehicleStatesComboBox(); }
public async Task <IActionResult> PutCustomerCard(Guid id, CustomerCard customerCard) { if (id != customerCard.Id) { return(BadRequest()); } _uow.CustomerCards.Update(customerCard); return(NoContent()); }
public async Task <IActionResult> TaskRemove(int id) { CustomerCardRow customerCardRow = await _customerCardRowManager.FindById(id); int routeId = customerCardRow.CustomerCardId; CustomerCard customerCard = await _customerCardManager.FindById(customerCardRow.CustomerCardId); customerCard.CostOfCardTime -= 4; await _customerCardManager.UpdateAsync(customerCard); await _customerCardRowManager.RemoveAsync(customerCardRow); return(RedirectToAction("Index", "Scrum", new { id = routeId })); }
public static string ImportCards(StationsDbContext context, string xmlString) { var sb = new StringBuilder(); var deserializedCards = XDocument.Parse(xmlString); var validCards = new List <CustomerCard>(); foreach (var element in deserializedCards.Root.Elements()) { var name = element.Element("Name")?.Value; var ageString = element.Element("Age")?.Value; if (String.IsNullOrWhiteSpace(ageString) || String.IsNullOrWhiteSpace(name)) { sb.AppendLine(FailureMessage); continue; } var age = int.Parse(ageString); if (age < 0 || age > 120 || name.Length > 128) { sb.AppendLine(FailureMessage); continue; } var cardTypeString = element.Element("CardType")?.Value; CardType cardType; if (cardTypeString != null) { cardType = Enum.Parse <CardType>(cardTypeString); } else { cardType = CardType.Normal; } var card = new CustomerCard() { Name = name, Age = age, Type = cardType }; validCards.Add(card); sb.AppendLine(string.Format(SuccessMessage, card.Name)); } context.Cards.AddRange(validCards); context.SaveChanges(); return(sb.ToString()); }
public static string ImportCards(StationsDbContext context, string xmlString) { var xmlSerializer = new XmlSerializer(typeof(CardDto[]), new XmlRootAttribute("Cards")); var deserializedCards = (CardDto[])xmlSerializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); var validCards = new List <CustomerCard>(); var sb = new StringBuilder(); foreach (var cardDto in deserializedCards) { if (!IsValid(cardDto)) { sb.AppendLine(FailureMessage); continue; } if (cardDto.Type == null) { cardDto.Type = "Normal"; } bool cardExists = validCards.Any(c => c.Name == cardDto.Name); if (cardExists) { sb.AppendLine(FailureMessage); continue; } var cardType = Enum.Parse <CardType>(cardDto.Type, true); CustomerCard customerCard = new CustomerCard { Type = cardType, Age = cardDto.Age, Name = cardDto.Name, }; validCards.Add(customerCard); sb.AppendLine(string.Format(SuccessMessage, customerCard.Name)); } context.Cards.AddRange(validCards); context.SaveChanges(); string result = sb.ToString().TrimEnd(); return(result); }
private static bool IsValidCard(CustomerCard card, StationsDbContext context) { //• Name – text with max length 128(required) // • Age – integer between 0 and 120 // • Type – CardType enumeration with values: "Normal", "Pupil", "Student", "Elder", "Debilitated"(default: Normal) if (card.Name.Length > 128) { return(false); } if (card.Age < 0 || card.Age > 120) { return(false); } return(true); }
public static string ImportCards(StationsDbContext context, string xmlString) { var sb = new StringBuilder(); var serializer = new XmlSerializer(typeof(List <ImportPersonCardDto>), new XmlRootAttribute("Cards")); var namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); var reader = new StringReader(xmlString); var personCardsToAdd = new List <CustomerCard>(); using (reader) { var customerCardDtos = (List <ImportPersonCardDto>)serializer.Deserialize(reader); foreach (var customerCardDto in customerCardDtos) { if (!IsValid(customerCardDto)) { sb.AppendLine(FailureMessage); continue; } var cardType = Enum.TryParse <CardType>(customerCardDto.CardType, out var card) ? card : CardType.Normal; var customerCard = new CustomerCard() { Name = customerCardDto.Name, Type = cardType, Age = customerCardDto.Age }; personCardsToAdd.Add(customerCard); sb.AppendLine(string.Format(SuccessMessage, customerCard.Name)); } context.CustomerCards.AddRange(personCardsToAdd); context.SaveChanges(); return(sb.ToString().Trim()); } }
public async Task <IActionResult> Create([Bind("Id,OwnerName,ContactNumber,Address,CardNumber,SubscribeDate", "PackageId", "SetBoxId")] CardAddModel model) { if (ModelState.IsValid) { CustomerCard customerCard = new CustomerCard() { Address = model.Address, SubscribeDate = model.SubscribeDate, CardNumber = model.CardNumber, ContactNumber = model.ContactNumber, OwnerName = model.OwnerName, Package = await _context.Packages.FirstOrDefaultAsync(p => p.Id == model.PackageId), SetBox = await _context.SetBoxes.FirstOrDefaultAsync(s => s.Id == model.SetBoxId) }; await _context.CustomerCards.AddAsync(customerCard); CustomerPackage cp = new CustomerPackage { CustomerCard = customerCard, NumberOfMonths = 0, ExpirationDate = DateTime.Now, Package = await _context.Packages.FirstOrDefaultAsync(p => p.Id == model.PackageId), Status = await _context.Status.SingleOrDefaultAsync(s => s.Name == "Recharged") }; await _context.CustomerPackages.AddAsync(cp); NewSetBoxRequest request = new NewSetBoxRequest() { Card = customerCard, Setbox = await _context.SetBoxes.FirstOrDefaultAsync(s => s.Id == model.SetBoxId), Status = await _context.Status.SingleOrDefaultAsync(s => s.Name == "AdminApproved") }; await _context.NewSetBoxRequest.AddAsync(request); var Subscriber = await _context.NewSubscribes. Include(s => s.Package). Include(s => s.SetBox). SingleOrDefaultAsync(s => s.Id == model.Id); _context.Update(Subscriber); Subscriber.Status = await _context.Status.FirstOrDefaultAsync(st => st.Name == "AdminApproved"); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult CreateCustomerCard(int? id, int? cardholderId, int? customerAccountId) { if (this.Request.IsPost()) { CustomerCard card = null; if (id == null) { card = new CustomerCard(); TryUpdateModel(card, new[] { "CardNumber" }); if (this.CustomerService.FindCustomerCardByCardNumber(card.CardNumber) != null) { ModelState.AddModelError("CardNumber", "该卡号已经存在."); } } else { card = this.CustomerService.FindCustomerCardById(id.GetValueOrDefault()); if (card == null) { throw new LogicalException(); } } if (cardholderId == null) { ModelState.AddModelError("CardholderId", "请输入持卡人."); } else { card.Cardholder = this.CustomerService.FindById(cardholderId.GetValueOrDefault()); if (card.Cardholder == null) { ModelState.AddModelError("CardholderId", "未找到该持卡人."); } } if (customerAccountId == null) { ModelState.AddModelError("CustomerAccountId", "请输入客户账户."); } else { card.CustomerAccount = this.CustomerService.FindCustomerAccountById(customerAccountId.GetValueOrDefault()); if (card.CustomerAccount == null) { ModelState.AddModelError("CustomerAccountId", "未找到该客户账户."); } } if (ModelState.IsValid) { this.CustomerService.SaveOrUpdateCustomerCard(card); return RedirectToAction("CustomerCardDetails", new { id = card.Id }); } return View("CustomerCard/Create", card); } return View("CustomerCard/Create"); }