public async Task <ActionResult> GetInterventions()
        {
            InterventionModel model = new InterventionModel();

            try
            {
                var email    = User.Identity.GetUserName();
                var path1    = $"{url}/Customers/{email}";
                var customer = await GetCustomerAsync(path1);

                if (customer != null)
                {
                    var buildings = await GetBuildingsAsync($"{url}/Buildings/{customer.Id}/net");

                    if (buildings != null)
                    {
                        foreach (var element in buildings)
                        {
                            model.Buildings.Add(new SelectListItem {
                                Text = element.AdmContactFullName, Value = element.Id.ToString()
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                int i = 0;
            }


            return(View("GetInterventions", model));
        }
        public async Task <ActionResult> CreateInterventions(InterventionModel model)
        {
            Interventions interv = new Interventions
            {
                Reports    = model.Reports,
                Author     = model.Author,
                CustomerId = model.CustomerId,
                BuildingId = long.Parse(model.BuildingId),
                BatteryId  = long.Parse(model.BatteryId),
                ColumnId   = long.Parse(model.ColumnId),
                ElevatorId = long.Parse(model.ElevatorId)
            };

            try
            {
                var httpClient = new HttpClient();
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                var response = await httpClient.PostAsync($"{url}/Interventions",
                                                          new StringContent(JsonConvert.SerializeObject(interv), Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                {
                    return(View("SuccessMessage"));
                }
            }
            catch (Exception e)
            {
                int i = 0;
            }

            return(View("Index"));
        }
        public async Task <ActionResult> GetElevators(string columnId)
        {
            long                  lcolumnId = long.Parse(columnId);
            List <Elevators>      elevators = new List <Elevators>();
            List <SelectListItem> items     = new List <SelectListItem>();


            var httpClient = new HttpClient();

            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            var response = await httpClient.GetAsync(requestUri : $"{url}/Elevators/{lcolumnId}/net");

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                elevators = JsonConvert.DeserializeObject <List <Elevators> >(result);
            }
            var model = new InterventionModel();

            if (elevators?.Count > 0)
            {
                foreach (var element in elevators)
                {
                    model.Elevators.Add(new SelectListItem {
                        Text = element.Id.ToString(), Value = element.Id.ToString()
                    });
                }
            }
            return(PartialView("_PartialSelectElevators", model));
        }
Пример #4
0
        public ActionResult Post(InterventionModel data)
        {
            using (var db = new RescContext())
            {
                var intervention = new Intervention {
                    Detail   = data.Detail,
                    Overview = data.Overview,
                    Lat      = data.Lat,
                    Lng      = data.Lng,
                    State    = IntervationState.Open
                };

                db.Interventions.Add(intervention);
                db.SaveChanges();
            }

            using (var db = new RescContext())
            {
                var intervention = db.Interventions.Where(i => i.State == IntervationState.Open).LastOrDefault();
                if (intervention != null)
                {
                    InterventionExtension.Notify(intervention);
                }
            }
            return(Ok());
        }