public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            double annualFee   = 0;
            double ratioToFull = 0;

            // if there are no errors in the membership data entered by user
            if (ModelState.IsValid)
            {
                // we retrieve the annual fee for the specified year from the AnnualFeeStructure table
                if (_context.AnnualFeeStructure
                    .SingleOrDefault(a => a.Year == membership.Year)
                    .AnnualFee != null)
                {
                    annualFee = (double)_context.AnnualFeeStructure
                                .SingleOrDefault(a => a.Year == membership.Year)
                                .AnnualFee;
                }
                // we retrieve the ratio to full for the specified membership type from the MembershipType table
                ratioToFull = _context.MembershipType.SingleOrDefault(a =>
                                                                      a.MembershipTypeName == membership.MembershipTypeName).RatioToFull;

                // we calculate the membership fee based on annual fee and ration to full
                membership.Fee = annualFee * ratioToFull;
                // and save the modified record to the database
                _context.Add(membership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            // for a year drop-down (to restrict the choice down to years for which we have annual fees)
            ViewData["MembershipYear"]     = new SelectList(_context.AnnualFeeStructure.OrderByDescending(m => m.Year), "Year", "Year");
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType.OrderBy(m => m.MembershipTypeName), "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
        public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure)
        {
            // Throw exception with any error use when they create a new record.
            // Display the TemData error at the top of the page.
            // Also keep the variable they input before submit.
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(annualFeeStructure);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                TempData["message"] = "Unable to create a new record.";
                return(View(annualFeeStructure));
            }
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("MemberId,FullName,FirstName,LastName,SpouseFirstName,SpouseLastName,Street,City,ProvinceCode,PostalCode,HomePhone,Email,YearJoined,Comment,TaskExempt,UseCanadaPost")] Member member)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(member);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "Member " + member.FullName + " was created";
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"error inserting new member: {ex.GetBaseException().Message}");
            }


            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", member.ProvinceCode);
            return(View(member));
        }
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            var annualFeeStructure = _context.AnnualFeeStructure
                                     .FirstOrDefault(a => a.Year == DateTime.Now.Year);

            if (annualFeeStructure == null)
            {
                TempData["message"] = "There is no annual fee for " + DateTime.Now.Year;
                return(RedirectToAction(nameof(Index)));
            }

            var membershipType = _context.MembershipType
                                 .FirstOrDefault(a => a.MembershipTypeName == membership.MembershipTypeName);

            //Calculate the fee for selected year and membershiptype
            double value = annualFeeStructure.AnnualFee * membershipType.RatioToFull;

            membership.Fee = value;

            if (ModelState.IsValid)
            {
                _context.Add(membership);
                await _context.SaveChangesAsync();

                TempData["message"] = "Membership " + membership.MembershipTypeName + " was created";
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["MemberId"]           = new SelectList(_context.Member, "MemberId", "FirstName", membership.MemberId);
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType, "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
 public async Task<IActionResult> Create([Bind("CountryCode,Name,PostalPattern,PhonePattern,FederalSalesTax")] Country country)
 {
     if (ModelState.IsValid)
     {
         _context.Add(country);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(country);
 }
        public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure)
        {
            if (ModelState.IsValid)
            {
                _context.Add(annualFeeStructure);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(annualFeeStructure));
        }
        public async Task <IActionResult> Create([Bind("TownName,ProvinceCode")] Town town)
        {
            if (ModelState.IsValid)
            {
                _context.Add(town);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(town));
        }
        public async Task <IActionResult> Create([Bind("MembershipTypeName,Description,RatioToFull")] MembershipType membershipType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(membershipType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(membershipType));
        }
        public async Task <IActionResult> Create([Bind("TaskId,Name,Description")] Tasks tasks)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tasks);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tasks));
        }
        public async Task <IActionResult> Create([Bind("BoatTypeId,Name,Description,Chargeable,Sail,Image")] BoatType boatType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(boatType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(boatType));
        }
        public async Task <IActionResult> Create([Bind("ProvinceCode,Name,CountryCode,TaxCode,TaxRate,Capital,IncludesFerderalTax")] Province province)
        {
            if (ModelState.IsValid)
            {
                _context.Add(province);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryCode"] = new SelectList(_context.Country, "CountryCode", "CountryCode", province.CountryCode);
            return(View(province));
        }
        public async Task <IActionResult> Create([Bind("MemberId,FullName,FirstName,LastName,SpouseFirstName,SpouseLastName,Street,City,ProvinceCode,PostalCode,HomePhone,Email,YearJoined,Comment,TaskExempt,UseCanadaPost")] Member member)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", member.ProvinceCode);
            return(View(member));
        }
        public async Task <IActionResult> Create([Bind("TownName,ProvinceCode")] Town town)
        {
            if (ModelState.IsValid)
            {
                _context.Add(town);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", town.ProvinceCode);
            return(View(town));
        }
Exemple #14
0
        public async Task <IActionResult> Create([Bind("ParkingCode,BoatTypeId,ActualBoatId")] Parking parking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(parking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoatTypeId"] = new SelectList(_context.BoatType, "BoatTypeId", "Name", parking.BoatTypeId);
            return(View(parking));
        }
Exemple #15
0
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(membership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MemberId"]           = new SelectList(_context.Member, "MemberId", "FirstName", membership.MemberId);
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType, "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
Exemple #16
0
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            // Get Memberid from session
            membership.MemberId = HttpContext.Session.GetInt32("MemberId").GetValueOrDefault();

            if (ModelState.IsValid)
            {
                // this is getting raw data from the DB (AnnualFeeStructure table)
                var annualFee = await _context.AnnualFeeStructure
                                .OrderByDescending(x => x.Year)
                                .FirstOrDefaultAsync();

                var membershipType = await _context.MembershipType.Where(x => x.MembershipTypeName == membership.MembershipTypeName).FirstOrDefaultAsync();

                var boatNumber = _context.Boat.Where(x => x.MemberId == membership.MemberId).Count();

                double boatFee = 0;

                // check boatFee with boat numbers
                if (boatNumber <= 1)
                {
                    boatFee = (double)annualFee.NonSailFee;
                }
                else if (boatNumber == 2)
                {
                    boatFee = (double)(annualFee.NonSailFee + annualFee.SecondBoatFee);
                }
                else if (boatNumber == 3)
                {
                    boatFee = (double)(annualFee.NonSailFee + annualFee.SecondBoatFee + annualFee.ThirdBoatFee);
                }

                else if (boatNumber > 3)
                {
                    boatFee = (double)(annualFee.NonSailFee + annualFee.SecondBoatFee + annualFee.ThirdBoatFee + annualFee.ForthAndSubsequentBoatFee);
                }

                // modify "membership.Fee" to calculae the actual fee
                membership.Fee = (float)(boatFee + annualFee.AnnualFee * membershipType.RatioToFull);

                // add to database
                _context.Add(membership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MemberId"]           = new SelectList(_context.Member, "MemberId", "FirstName", membership.MemberId);
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType.OrderBy(x => x.MembershipTypeName), "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);

            return(View(membership));
        }
Exemple #17
0
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(membership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            TempData["heading"]            = _context.Member.Include(b => b.ProvinceCodeNavigation).Where(b => b.MemberId == HttpContext.Session.GetInt32("memberId")).First().FullName;
            ViewData["MemberId"]           = new SelectList(_context.Member, "MemberId", "FirstName", membership.MemberId);
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType, "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
Exemple #18
0
        public async Task <IActionResult> Create([Bind("BoatId,MemberId,BoatClass,HullColour,SailNumber,HullLength,BoatTypeId,ParkingCode")] Boat boat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(boat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoatTypeId"]  = new SelectList(_context.BoatType, "BoatTypeId", "Name", boat.BoatTypeId);
            ViewData["MemberId"]    = new SelectList(_context.Member, "MemberId", "FirstName", boat.MemberId);
            ViewData["ParkingCode"] = new SelectList(_context.Parking, "ParkingCode", "ParkingCode", boat.ParkingCode);
            return(View(boat));
        }
        public async Task <IActionResult> Create([Bind("BoatId,MemberId,BoatClass,HullColour,SailNumber,HullLength,BoatTypeId,ParkingCode")] Boat boat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(boat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoatTypeId"] = new SelectList(_context.BoatType, "BoatTypeId", "Name", boat.BoatTypeId);
            ViewData["MemberId"]   = new SelectList(_context.Member, "MemberId", "FirstName", boat.MemberId);
            ViewData["heading"]    = _context.Member.Include(m => m.ProvinceCodeNavigation)
                                     .Where(m => m.MemberId == HttpContext.Session.GetInt32("memberId")).First().FullName;
            return(View(boat));
        }
Exemple #20
0
        public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(annualFeeStructure);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"Errors to Add New Record:{ex.GetBaseException().Message}");
            }
            return(View(annualFeeStructure));
        }
Exemple #21
0
        public async Task <IActionResult> Create([Bind("MemberId,FullName,FirstName,LastName,SpouseFirstName,SpouseLastName,Street,City,ProvinceCode,PostalCode,HomePhone,Email,YearJoined,Comment,TaskExempt,UseCanadaPost")] Member member)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(member);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Record for: {member.FullName} successfully added";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"Error: {ex.GetBaseException().Message}");
            }
            return(View(member));
        }
        public async Task <IActionResult> Create([Bind("MembershipTypeName,Description,RatioToFull")] MembershipType membershipType)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(membershipType);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(membershipType));
            }
            catch (Exception ex)
            {
                TempData["error"] = ex.GetBaseException().Message;
                return(RedirectToAction("Index", "BPMembershipType"));
            }
        }
Exemple #23
0
        public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure)
        {
            if (ModelState.IsValid)
            {
                var annualFees = _context.AnnualFeeStructure.Where(x => x.Year == annualFeeStructure.Year).FirstOrDefault();
                //Database does not auto increment, cannot allow creation for existing year
                if (annualFees != null)
                {
                    TempData["message"] = $"Annual Fee Structure already exists for {annualFeeStructure.Year.ToString()}";
                    return(RedirectToAction(nameof(Index)));
                }

                _context.Add(annualFeeStructure);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(annualFeeStructure));
        }
        public async Task <IActionResult> Create([Bind("ParkingCode,BoatTypeId,ActualBoatId")] Parking parking)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(parking);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "parking space added: " + parking.ParkingCode;
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"error adding boat: {ex.GetBaseException().Message}");
            }
            ViewData["BoatTypeId"] = new SelectList(_context.BoatType.OrderBy(a => a.Name), "BoatTypeId", "Name", parking.BoatTypeId);
            return(View(parking));
        }
Exemple #25
0
        public async Task <IActionResult> Create([Bind("BoatId,MemberId,BoatClass,HullColour,SailNumber,HullLength,BoatTypeId,ParkingCode")] Boat boat)
        {
            boat.MemberId = HttpContext.Session.GetInt32("MemberId");
            if (ModelState.IsValid)
            {
                _context.Add(boat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoatTypeId"]  = new SelectList(_context.BoatType.OrderBy(x => x.Name), "BoatTypeId", "Name", boat.BoatTypeId);
            ViewData["MemberId"]    = new SelectList(_context.Member, "MemberId", "FirstName", boat.MemberId);
            ViewData["ParkingCode"] = new SelectList(_context.Parking
                                                     .Where(x => string.IsNullOrEmpty(x.ActualBoatId)), "ParkingCode", "ParkingCode", boat.ParkingCode)
                                      .Prepend(new SelectListItem()
            {
                Value = "null", Text = ""
            });
            return(View(boat));
        }
Exemple #26
0
        public async Task <IActionResult> Create([Bind("BoatId,MemberId,BoatClass,HullColour,SailNumber,HullLength,BoatTypeId,ParkingCode")] Boat boat)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(boat);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "new boat added: " + boat.BoatId;
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"error adding new boat: {ex.GetBaseException().Message}");
            }
            Create();
            return(View(boat));
        }
        public async Task <IActionResult> Create([Bind("BoatId,MemberId,BoatClass,HullColour,SailNumber,HullLength,BoatTypeId,ParkingCode")] Boat boat)
        {
            boat.MemberId = HttpContext.Session.GetInt32("MemberId");
            var fullname = _context.Member
                           .Where(x => x.MemberId == boat.MemberId)
                           .FirstOrDefault();

            ViewBag.FullName = fullname.FullName;
            if (ModelState.IsValid)
            {
                _context.Add(boat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoatTypeId"]  = new SelectList(_context.BoatType.OrderBy(x => x.Name), "BoatTypeId", "Name", boat.BoatTypeId);
            ViewData["MemberId"]    = new SelectList(_context.Member, "MemberId", "FirstName", boat.MemberId);
            ViewData["ParkingCode"] = new SelectList(_context.Parking, "ParkingCode", "ParkingCode", boat.ParkingCode);
            return(View(boat));
        }
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            if (ModelState.IsValid)
            {
                var fee = (from record in _context.AnnualFeeStructure
                           where record.Year == DateTime.Now.Year
                           select record.AnnualFee).SingleOrDefault();

                var ratio = (from record in _context.MembershipType
                             where record.MembershipTypeName == membership.MembershipTypeName
                             select record.RatioToFull).SingleOrDefault();
                membership.Fee = Convert.ToDouble(fee) * Convert.ToDouble(ratio);
                _context.Add(membership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MemberId"]           = new SelectList(_context.Member, "MemberId", "FirstName", membership.MemberId);
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType.OrderBy(a => a.MembershipTypeName), "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
Exemple #29
0
        public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(annualFeeStructure);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "Annual Fee " + annualFeeStructure.Year + " was created";
                    return(RedirectToAction(nameof(Index)));
                }

                return(View(annualFeeStructure));
            }
            catch (Exception ex)
            {
                TempData["message"] = "An error ocorred, please try again";
                return(View());
            }
        }
        public async Task <IActionResult> Create([Bind("MemberId,FullName,FirstName,LastName,SpouseFirstName,SpouseLastName,Street,City,ProvinceCode,PostalCode,HomePhone,Email,YearJoined,Comment,TaskExempt,UseCanadaPost")] Member member)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(member);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "New Member record has been created Successfully";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.GetBaseException().Message);
                TempData["message"] = "Error occurred while creating a new member record " + e.GetBaseException().Message;
            }

            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", member.ProvinceCode);
            return(View(member));
        }