Esempio n. 1
0
        public ActionResult Login(Customer customer)
        {
            if (ModelState.IsValid)
            {
                using (HomeDepotContext context = new HomeDepotContext())
                {
                    //probably doesnt work

                    var cust = context.Customers.ToList().Find(c => c.Email.Equals(customer.Email) && c.Password.Equals(customer.Password));
                    if (cust != null)
                    {
                        CustomerPageViewModel customerPage = new CustomerPageViewModel();
                        customerPage.Customer   = cust;
                        customerPage.Bookings   = context.Bookings.ToList().FindAll(b => b.CustomerId == cust.CustomerId);
                        customerPage.Tools      = context.Tools.ToList();
                        Session["customerPage"] = customerPage;
                        return(View("CustomerPage", customerPage));
                    }
                    else
                    {
                        ViewBag.Error = "Invalid login info";
                    }
                }
            }
            return(View("Login"));
        }
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="Common.NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            var vm = new CustomerPageViewModel();

            vm.Customer      = e.NavigationParameter as Customer;
            this.DataContext = vm;
        }
Esempio n. 3
0
        public ActionResult Create(IndividualCustomer person)
        {
            CustomerPageViewModel pageViewModel = new CustomerPageViewModel(this);
            IEnumerable <string>  titles        = GetTitles();
            IEnumerable <string>  genders       = GetGenders();

            person.TitleList          = GetSelectListItems(titles);
            person.GenderList         = GetSelectListItems(genders);
            person.GetCards           = GetCards();
            person.GetState           = GetState();
            person.AddressIding       = AddressIding();
            person.Emailnotifications = Emailnotifictions();
            person.Phonetype          = Phonetype();
            try
            {
                if (ModelState.IsValid)
                {
                    pageViewModel.InsertCustomer(person);
                    unit.Save();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save to db");
                    return(View(person));
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(View(person));
        }
Esempio n. 4
0
        public ViewResult Details(int BusinessEntityID)
        {
            IndividualCustomer    person        = new IndividualCustomer();
            CustomerPageViewModel pageViewModel = new CustomerPageViewModel(this);

            person = pageViewModel.SingleCustomer(BusinessEntityID);
            return(View(person));
        }
Esempio n. 5
0
        // GET: Customer
        public ActionResult Index(string searchString)
        {
            CustomerPageViewModel pageViewModel = new CustomerPageViewModel(this);
            var people     = pageViewModel.Build();
            var personList = people;

            if (!String.IsNullOrEmpty(searchString))
            {
                people = personList.Where(x => x.FirstName.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0 || x.LastName.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0);
            }
            return(View(people));
        }
Esempio n. 6
0
        public ActionResult CustomerPage(CustomerPageViewModel customerPage)
        {
            if (Session["customerPage"] != null)
            {
                CustomerPageViewModel sCustomerPage = Session["customerPage"] as CustomerPageViewModel;
                using (HomeDepotContext context = new HomeDepotContext())
                {
                    sCustomerPage.Bookings = context.Bookings.ToList().FindAll(b => b.CustomerId == sCustomerPage.Customer.CustomerId);
                }

                return(View(Session["customerPage"] as CustomerPageViewModel));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Esempio n. 7
0
        public ActionResult CreateBooking(Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateBooking"));
            }

            using (HomeDepotContext context = new HomeDepotContext())
            {
                //skal gemme en booking i db og redirecte til customerpage (eventuelt besked med at booking er oprettet + fejl beskeder for variabler)

                string         selectedTool = Request.Form["ToolNames"].ToString();
                Tool           tool         = context.Tools.ToList().Find(t => t.Name.Equals(selectedTool));
                List <Booking> toolBookings = context.Bookings.ToList().FindAll(b => b.ToolId == tool.ToolId);
                foreach (var b in toolBookings)
                {
                    for (int i = 0; i < b.Days; i++)
                    {
                        if (b.PickupDay.AddDays(i) == booking.PickupDay && b.PickupDay == booking.PickupDay.AddDays(i))
                        {
                            ViewBag.Error = "Tool already booked for this period \n Available after: " + b.PickupDay.ToString("dd/MM/yyy/");
                            return(View());
                        }
                    }
                }
                if (Session["customerPage"] == null)
                {
                    return(View("Login"));
                }
                else
                {
                    CustomerPageViewModel customerPage = Session["customerPage"] as CustomerPageViewModel;
                    context.Bookings.Add(new Booking {
                        PickupDay = booking.PickupDay, CustomerId = customerPage.Customer.CustomerId, Status = "Reserveret", Days = booking.Days, ToolId = tool.ToolId
                    });
                    context.SaveChanges();
                }
            }
            return(RedirectToAction("Customerpage", Session["customerPage"]));
            //return View("CustomerPage", Session["customerPage"]);
        }
Esempio n. 8
0
        public ActionResult Edit(int BusinessEntityID)
        {
            IndividualCustomer    person        = new IndividualCustomer();
            CustomerPageViewModel pageViewModel = new CustomerPageViewModel(this);
            IEnumerable <string>  titles        = GetTitles();
            IEnumerable <string>  genders       = GetGenders();

            person.TitleList          = GetSelectListItems(titles);
            person.GenderList         = GetSelectListItems(genders);
            person.GetCards           = GetCards();
            person.GetState           = GetState();
            person.AddressIding       = AddressIding();
            person.Emailnotifications = Emailnotifictions();
            person.Phonetype          = Phonetype();
            person = pageViewModel.SingleCustomer(BusinessEntityID);
            if (person == null)
            {
                return(HttpNotFound());
            }
            return(View(person));
        }
Esempio n. 9
0
        public ActionResult Edit(IndividualCustomer person)
        {
            CustomerPageViewModel pageViewModel = new CustomerPageViewModel(this);
            IEnumerable <string>  titles        = GetTitles();
            IEnumerable <string>  genders       = GetGenders();

            person.TitleList          = GetSelectListItems(titles);
            person.GenderList         = GetSelectListItems(genders);
            person.GetCards           = GetCards();
            person.GetState           = GetState();
            person.AddressIding       = AddressIding();
            person.Emailnotifications = Emailnotifictions();
            person.Phonetype          = Phonetype();
            try
            {
                if (ModelState.IsValid)
                {
                    pageViewModel.UpdateCustomer(person);
                    unit.Save();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save to db");
                    return(View(person));
                }
            }
            catch (DbEntityValidationException e)
            {
                var r = e.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                var fullErrorText = string.Join(";", r);
                var exeptionText  = string.Concat(e.Message, "Your Errors are: ", fullErrorText);

                ModelState.AddModelError("", exeptionText);
            }
            return(View(person));
        }