コード例 #1
0
        public async Task <IActionResult> PutPackages(int id, Packages packages)
        {
            if (id != packages.PackageId)
            {
                return(BadRequest());
            }

            _context.Entry(packages).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PackagesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,CustFirstName,CustLastName,CustAddress,CustCity,CustProv,CustPostal,CustCountry,CustHomePhone,CustBusPhone,CustEmail,AgentId,Username,Password")] Customers customers)
        {
            if (id != customers.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomersExists(customers.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Profile)));
            }
            ViewData["AgentId"] = new SelectList(_context.Agents, "AgentId", "AgentId", customers.AgentId);
            return(View(customers));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("CustomerId,CustFirstName,CustLastName,CustAddress,CustCity,CustProv,CustPostal,CustCountry,CustHomePhone,CustBusPhone,CustEmail,AgentId,PasswordNotHashed,PasswordHashed,PasswordSalt")] Customers customers)
        {
            var customer = from b in _context.Customers
                           where b.CustEmail.Equals(customers.CustEmail)
                           select b;

            if (customer.Count() > 0)
            {
                return(View("~/Views/Home/Index.cshtml"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(customers);
                    Debug.WriteLine(_context.Customers);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("userEmail", customers.CustEmail);
                    return(Redirect("~/"));
                }
            }

            return(View(customers));
        }
コード例 #4
0
        // Edits the customer given the old customer and new customer
        public async Task <Customers> EditCustomer(Customers oldCustomer, CustomerForUpdateDto newCustomer)
        {
            // Gets old customer from db, ensures that customer has not been changed (for updatable properties)
            var oldCustomerFromDB = await context.Customers
                                    .Where(c =>
                                           (c.CustomerId == oldCustomer.CustomerId) &&
                                           (c.CustAddress == oldCustomer.CustAddress) &&
                                           (c.CustCity == oldCustomer.CustCity) &&
                                           (c.CustCountry == oldCustomer.CustCountry) &&
                                           (c.CustFirstName == oldCustomer.CustFirstName) &&
                                           (c.CustLastName == oldCustomer.CustLastName) &&
                                           (c.CustPostal == oldCustomer.CustPostal) &&
                                           (c.CustProv == oldCustomer.CustProv) &&
                                           (c.CustHomePhone == oldCustomer.CustHomePhone) &&
                                           (c.CustBusPhone == oldCustomer.CustBusPhone) &&
                                           (c.CustEmail == oldCustomer.CustEmail)
                                           ).FirstOrDefaultAsync();

            if (oldCustomerFromDB != null)
            {
                mapper.Map(newCustomer, oldCustomerFromDB); // Assigns new customer properties to old customer
                await context.SaveChangesAsync();           // Saves changes
            }
            return(oldCustomerFromDB);                      // Returns updated customer from db
        }
コード例 #5
0
        public async Task <IActionResult> PutSuppliers(int id, Suppliers suppliers)
        {
            if (id != suppliers.SupplierId)
            {
                return(BadRequest());
            }

            _context.Entry(suppliers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SuppliersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("AgencyId,AgncyAddress,AgncyCity,AgncyProv,AgncyPostal,AgncyCountry,AgncyPhone,AgncyFax")] Agencies agencies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(agencies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(agencies));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("PackageId,PkgName,PkgStartDate,PkgEndDate,PkgDesc,PkgBasePrice,PkgAgencyCommission")] Packages packages)
        {
            if (ModelState.IsValid)
            {
                _context.Add(packages);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(packages));
        }
コード例 #8
0
ファイル: AgentsController.cs プロジェクト: Mibsling/mvctest
        public async Task <IActionResult> Create([Bind("AgentId,AgtFirstName,AgtMiddleInitial,AgtLastName,AgtBusPhone,AgtEmail,AgtPosition,AgencyId")] Agents agents)
        {
            if (ModelState.IsValid)
            {
                _context.Add(agents);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(agents));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("CustomerId,CustFirstName,CustLastName,CustAddress,CustCity,CustProv,CustPostal,CustCountry,CustHomePhone,CustBusPhone,CustEmail,Username,Password,ConfirmPassword,AgentId")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Bookings"));
            }
            //ViewData["AgentId"] = new SelectList(_context.Agents, "AgentId", "AgentId", customers.AgentId);
            return(View(customers));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("BookingId,BookingDate,BookingNo,TravelerCount,CustomerId,TripTypeId,PackageId")] Bookings bookings)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bookings);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustAddress", bookings.CustomerId);
            ViewData["PackageId"]  = new SelectList(_context.Packages, "PackageId", "PkgName", bookings.PackageId);
            ViewData["TripTypeId"] = new SelectList(_context.TripTypes, "TripTypeId", "TripTypeId", bookings.TripTypeId);
            return(View(bookings));
        }
コード例 #11
0
        // Registers customer given customer model and password
        public async Task <Customers> Register(Customers customer, string password)
        {
            byte[] passwordSalt; // stores password salt
            byte[] passwordHash; // stores password hash

            // Generates hash and salt from password
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            // Assigns password and salt to customer
            customer.Password = Convert.ToBase64String(passwordHash);
            customer.Salt     = Convert.ToBase64String(passwordSalt);

            // Adds customer and saves changes
            await context.Customers.AddAsync(customer);

            await context.SaveChangesAsync();

            return(customer); // returns registered customer
        }
コード例 #12
0
        ////
        /// <summary>
        /// Add a new customer to database.
        /// </summary>
        /// <param name="newCust">Customers object need to be added.</param>
        /// <returns>A bool indicate if added successfully.</returns>
        public static async Task <bool> Add(Customers newCust)
        {
            bool isSucceed = false;
            var  context   = new TravelExpertsContext();

            context.Customers.Add(newCust);
            try
            {
                int i = await context.SaveChangesAsync();

                if (i > 0)
                {
                    isSucceed = true;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(isSucceed);
        }