Example #1
0
        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("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("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));
        }
Example #4
0
        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));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("CountryCode,Name,PhonePattern,PostalPattern")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(country));
        }
Example #6
0
        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("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));
        }
Example #9
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));
        }
        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));
        }
Example #11
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));
        }
Example #12
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));
        }
Example #13
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));
        }
Example #14
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));
        }
Example #16
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));
        }
        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"));
            }
        }
Example #18
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));
        }
Example #19
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("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));
        }
Example #21
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));
        }
Example #23
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));
        }
        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));
        }
        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 has been added successfully";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.GetBaseException().Message);
                TempData["message"] = ex.GetBaseException().Message;
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", member.ProvinceCode);
            return(View(member));
        }
Example #26
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());
            }
        }
Example #27
0
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            if (ModelState.IsValid)
            {
                var    annualFee     = _context.AnnualFeeStructure.Where(x => x.Year == membership.Year).First();
                double discount      = _context.MembershipType.Where(x => x.MembershipTypeName == membership.MembershipTypeName).Select(x => x.RatioToFull).First();
                int    numberOfBoats = _context.Boat.Where(x => x.MemberId == membership.MemberId).Count();

                float totalFee = (float)annualFee.AnnualFee;


                if (numberOfBoats > 1)
                {
                    switch (numberOfBoats)
                    {
                    case 2:
                        totalFee += (float)annualFee.SecondBoatFee;
                        break;

                    case 3:
                        totalFee += (float)annualFee.SecondBoatFee + (float)annualFee.ThirdBoatFee;
                        break;

                    default:
                        totalFee += (float)annualFee.SecondBoatFee + (float)annualFee.ThirdBoatFee + (float)annualFee.ForthAndSubsequentBoatFee * (numberOfBoats - 3);
                        break;
                    }
                }

                membership.Fee = (float)(totalFee * discount);

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MembershipTypeName"] = new SelectList(_context.MembershipType.OrderBy(x => x.MembershipTypeName), "MembershipTypeName", "MembershipTypeName", membership.MembershipTypeName);
            return(View(membership));
        }
Example #28
0
        public async Task <IActionResult> Create([Bind("MembershipId,MemberId,Year,MembershipTypeName,Fee,Comments,Paid")] Membership membership)
        {
            if (ModelState.IsValid)
            {
                double?fee         = _context.AnnualFeeStructure.Where(y => y.Year == DateTime.Today.Year).ToList()[0].AnnualFee;
                double?percentPaid = _context.MembershipType.Where(m => m.MembershipTypeName == membership.MembershipTypeName).ToList()[0].RatioToFull;

                ViewData["fee"] = fee * percentPaid;
                membership.Fee  = (double)fee * (double)percentPaid;

                _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));
        }
        public async Task <IActionResult> Create([Bind("MemberId,FullName,FirstName,LastName,SpouseFirstName,SpouseLastName,Street,City,ProvinceCode,PostalCode,HomePhone,Email,YearJoined,Comment,TaskExempt,UseCanadaPost")] Member member)
        {
            // the try catch statement
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(member);
                    await _context.SaveChangesAsync();

                    TempData["message"] = "New Record Added"; // adding on success tempdata message
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                // on error add model into modelstate
                ModelState.AddModelError("", $"Error on saving create: " + $"{ex.GetBaseException().Message}");
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", member.ProvinceCode);
            return(View(member));
        }
        public async Task <IActionResult> Create([Bind("ProvinceCode,Name,CountryCode,TaxCode,TaxRate,Capital,IncludesFerderalTax")] Province province)
        {
            try
            {
                await TryUpdateModelAsync(province);

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

                    TempData["message"] = "New province created successfully..";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                TempData["message"] = "Error creating new province: " + ex.GetBaseException().Message;
            }

            ViewData["CountryCode"] = new SelectList(_context.Country, "CountryCode", "CountryCode", province.CountryCode);
            return(View(province));
        }