Example #1
0
        public ActionResult Create(status NewStatus)
        {
            _switch sw = (from r in repository.switches where r.switchID == NewStatus.switchID select r).FirstOrDefault();

            //find out closest date
            var lastStatus = (from q in sw.status
                              let distance = q.datetime.Subtract(NewStatus.datetime).Ticks
                                             orderby distance descending
                                             select q).First();

            if (NewStatus.action != lastStatus.action && NewStatus.datetime > lastStatus.datetime)
            {
                NewStatus._switch = sw;
                repository.SaveStatus(NewStatus);

                TempData["SuccessMessage"] = string.Format("Успешно сохранено {0} для {1} в {2}",
                                                           (NewStatus.action == "-1" ? "Down" : "Up"),
                                                           NewStatus._switch.Name,
                                                           NewStatus.datetime);

                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["ErrorMessage"] = string.Format("Некорректный ввод - {0} последний раз был {1} в {2}",
                                                         lastStatus._switch.Name,
                                                         (lastStatus.action == "-1" ? "Down" : "Up"),
                                                         lastStatus.datetime);
                return(RedirectToAction("Create"));
            }
        }
 set => SetProperty(ref _switch, value);