Beispiel #1
0
        public ActionResult Edit(ScheduleViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var validate = RestIntegration.Get <ApiReturnItem <Boolean> >("http://localhost:54878/", $"/api/Schedules/Validate/{model.Day.Value:yyyy-MM-dd}/{model.Hour}/{model.ScheduleId}");

                    if (!(validate?.Item).GetValueOrDefault(false))
                    {
                        var result = RestIntegration.Put <ScheduleRequest, ApiReturnList <ScheduleResult> >(
                            "http://localhost:54878/", "/api/Schedules", new ScheduleRequest
                        {
                            Day        = model.Day.Value,
                            Hour       = model.Hour.Value,
                            ScheduleId = model.ScheduleId,
                            ServiceId  = model.ServiceId,
                            CustomerId = model.CustomerId
                        });

                        return(RedirectToAction(nameof(Index)));
                    }

                    ModelState.AddModelError(String.Empty, "Já existe agendamento no dia e horário escolhido");
                }

                MakeDropdownsViewbags(model.Hour, model.CustomerId, model.ServiceId);
                return(View(model));
            }
            catch (Exception e)
            {
                MakeDropdownsViewbags(model.Hour, model.CustomerId, model.ServiceId);
                return(View(model));
            }
        }
Beispiel #2
0
        private IEnumerable <SelectListItem> MakeCustomersDropDownList(Guid?customerId = null)
        {
            var customers = RestIntegration.Get <ApiReturnList <CustomerResult> >("http://localhost:54878/", "/api/Customers");

            return(customers?.Items.Select(s => new SelectListItem
            {
                Text = s.Name,
                Selected = customerId.HasValue && s.CustomerId == customerId,
                Value = s.CustomerId.ToString()
            }));
        }
Beispiel #3
0
 public ActionResult Delete(Guid id)
 {
     try
     {
         var Service = RestIntegration.Delete("http://localhost:54878/", $"/api/Schedules/{id}");
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(RedirectToAction(nameof(Index)));
     }
 }
Beispiel #4
0
        private IEnumerable <SelectListItem> MakeServicesDropDownList(Guid?serviceId = null)
        {
            var services = RestIntegration.Get <ApiReturnList <ServiceResult> >("http://localhost:54878/", "/api/Services");

            ViewBag.EntityServices = services?.Items ?? new List <ServiceResult>();

            return(services?.Items.Select(s => new SelectListItem
            {
                Text = s.Name,
                Selected = serviceId.HasValue && s.ServiceId == serviceId,
                Value = s.ServiceId.ToString()
            }));
        }
Beispiel #5
0
        // GET: Schedules/Edit/5
        public ActionResult Edit(Guid id)
        {
            var schedule = RestIntegration.Get <ApiReturnItem <ScheduleResult> >("http://localhost:54878/", $"/api/Schedules/{id}");

            MakeDropdownsViewbags(schedule?.Item?.Hour, schedule?.Item?.Customer?.CustomerId, schedule?.Item?.Service?.ServiceId);
            var model = schedule?.Item;

            return(View(new ScheduleViewModel
            {
                Day = model.Day,
                Hour = model.Hour,
                ScheduleId = model.ScheduleId,
                ServiceId = model.ServiceId,
                CustomerId = model.CustomerId,
                Customer = model.Customer,
                Service = model.Service
            }));
        }
Beispiel #6
0
        public ActionResult Edit(ServiceResult model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = RestIntegration.Put <ServiceResult, ApiReturnList <ServiceResult> >("http://localhost:54878/", "/api/Services", model);

                    return(RedirectToAction(nameof(Index)));
                }

                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }
Beispiel #7
0
        public ActionResult Create(CustomerResult model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = RestIntegration.Post <CustomerResult, ApiReturnList <CustomerResult> >("http://localhost:54878/", "/api/Customers", model);

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }
Beispiel #8
0
        // GET: Schedules
        public ActionResult Index()
        {
            var Schedules = RestIntegration.Get <ApiReturnList <ScheduleResult> >("http://localhost:54878/", "/api/Schedules");

            return(View(Schedules?.Items));
        }
Beispiel #9
0
        // GET: Services/Edit/5
        public ActionResult Edit(Guid id)
        {
            var Service = RestIntegration.Get <ApiReturnItem <ServiceResult> >("http://localhost:54878/", $"/api/Services/{id}");

            return(View(Service?.Item));
        }
Beispiel #10
0
        // GET: Customers/Edit/5
        public ActionResult Edit(Guid id)
        {
            var customer = RestIntegration.Get <ApiReturnItem <CustomerResult> >("http://localhost:54878/", $"/api/Customers/{id}");

            return(View(customer?.Item));
        }
Beispiel #11
0
        // GET: Customers
        public ActionResult Index()
        {
            var customers = RestIntegration.Get <ApiReturnList <CustomerResult> >("http://localhost:54878/", "/api/Customers");

            return(View(customers?.Items));
        }