public async Task <IActionResult> RegisterMember(RegisterMemberViewModel viewModel) { if (ModelState.IsValid) { var member = new Member { FirstName = viewModel.FirstName, LastName = viewModel.LastName, Email = viewModel.Email, PhoneNum = viewModel.PhoneNum }; if (!EmailExists(viewModel.Email)) { _context.Add(member); await _context.SaveChangesAsync(); } else { return(Json($"{viewModel.Email} is in use")); } return(RedirectToAction(nameof(MemberOverView))); } return(View(viewModel)); }
public async Task <IActionResult> RegisterNewVehicle([Bind("MemberID,LicenseNumber,VehicleType,Color,Brand,Model,NumberOfWheels")] RegisterNewVehicleViewModel vh) { var vehicle = new Vehicle(); vehicle.LicenseNumber = vh.LicenseNumber.ToUpper(); vehicle.Brand = vh.Brand; vehicle.Color = vh.Color; vehicle.Model = vh.Model; vehicle.NumberOfWheels = vh.NumberOfWheels; var owner = db.Member.Where(m => m.MemberID == Int32.Parse(vh.MemberID)).FirstOrDefault(); var vehicleType = db.VehicleType.Where(v => v.Type == vh.VehicleType).FirstOrDefault(); vehicle.Owner = owner; vehicle.VehicleType = vehicleType; if (ModelState.IsValid) { db.Add(vehicle); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicle)); }
public async Task <IActionResult> Park([Bind("Id,RegNumber,TimeOfParking,Color,NumberOfWheels,Brand,Model,VehicleTypesId,MembersId")] Vehicles vehicles) { if (ModelState.IsValid) { vehicles.TimeOfParking = DateTime.Now; // Check whether the Vehicle with same Registration Number is Parked or not var findRegistrationNr = _context.Vehicles .Where(rn => rn.RegNumber == vehicles.RegNumber).ToList(); if (findRegistrationNr.Count == 0) { _context.Add(vehicles); } else { ModelState.AddModelError("RegNumber", "Vehicle with same Registration Number is already Parked"); ViewData["MembersId"] = new SelectList(_context.Set <Members>(), "Id", "FullName"); ViewData["VehicleTypesId"] = new SelectList(_context.Set <VehicleTypes>(), "Id", "TypeOfVehicle"); return(View(vehicles)); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MembersId"] = new SelectList(_context.Set <Members>(), "Id", "FullName"); ViewData["VehicleTypesId"] = new SelectList(_context.Set <VehicleTypes>(), "Id", "TypeOfVehicle"); return(View(vehicles)); }
public async Task <IActionResult> RegisterNewMember([Bind("MemberID,PersonalIdentityNumber,FirstName,LastName,Joined,ExtendedMemberShipEndDate")] Member member) { if (ModelState.IsValid) { member.Joined = DateTime.Now; // todo: refactor to method string PINformat = Regex.Replace(member.PersonalIdentityNumber, @"[^0-9]", ""); string PINDate = PINformat.Substring(0, 8); DateTime customerAge = DateTime.ParseExact(PINDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); // give automatic pro membership at join if (customerAge < DateTime.Now.AddYears(-65)) { member.ExtendedMemberShipEndDate = DateTime.Now.AddYears(2); } else { member.ExtendedMemberShipEndDate = DateTime.Now.AddDays(30); } member.MembershipType = db.MembershipType.Where(m => m.Type == "Pro").FirstOrDefault(); db.Add(member); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("MembershiptTypeID,Type,Discount")] MembershipType membershipType) { if (ModelState.IsValid) { db.Add(membershipType); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(membershipType)); }
public async Task <IActionResult> Create([Bind("Type,Size,imgSrc")] VehicleType vehicleType) { if (ModelState.IsValid) { db.Add(vehicleType); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicleType)); }
public async Task <IActionResult> Create([Bind("Id,PersonNr,FristName,LastName")] Members members) { if (ModelState.IsValid) { var findPersonNumber = _context.Members .Where(rn => rn.PersonNr == members.PersonNr).ToList(); if (findPersonNumber.Count == 0) { _context.Add(members); } else { ModelState.AddModelError("PersonNr", "Member with same Person Number already Exist"); return(View()); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(members)); }