Ejemplo n.º 1
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var customer = customerData.GetCustomerById(Visit.CustomoerId.Value);
                Visit.Customer = customer;

                Visit = visitData.Create(Visit);
                TempData["Message"] = "The Visit is Created";
                visitData.Commit();
                return(RedirectToPage("./List"));
            }
            var customers = customerData.GetCustomers().ToList().Select(c => new { Id = c.Id, Display = $"{c.FirstName} {c.LastName}" });

            Customers = new SelectList(customers, "Id", "Display");
            return(Page());
        }
Ejemplo n.º 2
0
 public IActionResult OnGet(int id)
 {
     Customer = customerData.GetCustomerById(id);
     if (Customer == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Ejemplo n.º 3
0
        public IActionResult GetCustomers(int id)
        {
            var data = customerData.GetCustomerById(id);

            if (data == null)
            {
                return(NotFound());
            }
            return(Ok(data));
        }
Ejemplo n.º 4
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var customer = customerData.GetCustomerById(Purchase.CustomerId.Value);
                Purchase.Customer = customer;

                Purchase = purchaseData.Create(Purchase);
                TempData["TempMessage"] = "Purchase is registered!";

                purchaseData.Commit();
                return(RedirectToPage("./List"));
            }

            var customers = customerData.GetCustomers().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" });

            Customers = new SelectList(customers, "Id", "Display");
            return(Page());
        }
        public IActionResult GetMemebrshipByCustomerId(int customerId)
        {
            var custoemr = customerData.GetCustomerById(customerId);

            if (custoemr == null)
            {
                return(NotFound());
            }

            return(Ok(custoemr.Membership));
        }
Ejemplo n.º 6
0
        public IActionResult Edit(int?id)
        {
            var model = new CustomersEditViewModel();

            if (id.HasValue)
            {
                model.Customer = customerData.GetCustomerById(id.Value);
                if (model.Customer == null)
                {
                    return(View("NotFound"));
                }
            }
            else
            {
                model.Customer = new Customer();
            }
            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            model.Memberships = new SelectList(memberships, "Id", "Display");
            model.Gender      = htmlHelper.GetEnumSelectList <Gender>();
            model.City        = htmlHelper.GetEnumSelectList <City>();
            return(View(model));
        }
Ejemplo n.º 7
0
 public IActionResult OnGet(int? Id)
 {
     if (Id.HasValue)
     {
         Customer = customerData.GetCustomerById(Id.Value);
         if(Customer == null)
         {
             return RedirectToPage("./NotFound");
         }
     }
     else
     {
         Customer = new Customer();
     }
     var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });
     Memberships = new SelectList(memberships, "Id", "Display");
     return Page();
 }
Ejemplo n.º 8
0
        public IActionResult Create(VisitDto visitDto)
        {
            var customer = customerData.GetCustomerById(visitDto.CustomerId.GetValueOrDefault());

            if (customer == null)
            {
                return(BadRequest());
            }

            var visit = new Visit();

            visit.CustomerId = visitDto.CustomerId;

            var shopItemsValues = (IEnumerable <int>)Enum.GetValues(typeof(ShopItemType));

            foreach (var shopItem in visitDto.ShopItems)
            {
                if (!shopItemsValues.Any(x => x == shopItem.ShopItemType))
                {
                    ModelState.AddModelError("ShopItemType", $"ShopItemType[{visitDto.ShopItems.IndexOf(shopItem)}] {shopItem.ShopItemType} does not exists.");
                }

                if (ModelState.IsValid)
                {
                    visit.ShopItems.Add(new ShopItem
                    {
                        Price        = Math.Abs(shopItem.Price.GetValueOrDefault()),
                        ShopItemType = (ShopItemType)shopItem.ShopItemType
                    });
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationProblemDetails(ModelState)));
                //return BadRequest(ModelState);
            }


            visitData.Create(visit);
            visitData.Commit();
            return(CreatedAtRoute("FetchVisit", new { id = visit.Id }, visit));
        }
Ejemplo n.º 9
0
        public IActionResult OnGet(int?id)
        {
            if (id.HasValue)
            {
                Customer = customerData.GetCustomerById(id.Value);
                if (Customer == null)
                {
                    return(RedirectToPage("./NotFound"));
                }
            }
            else
            {
                Customer = new Core.Customer();
            }

            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            Memberships = new SelectList(memberships, "Id", "Display");
            Gender      = htmlHelper.GetEnumSelectList <Gender>();
            City        = htmlHelper.GetEnumSelectList <City>();
            return(Page());
        }
Ejemplo n.º 10
0
 public IActionResult GetById(int id)
 {
     return(Ok(customerData.GetCustomerById(id)));
 }