Beispiel #1
0
        public ActionResult <BaseResponse> UpdateStatus(DetailedStatus status)
        {
            try
            {
                _statusService.AddOrUpdate(status);

                if (status.Id != 0)
                {
                    var oldStatus = _statusService.Get(status.Id);
                    var newStatus = _statusService.Get(status.Status);
                    _deviceService.UpdateStatuses(newStatus, oldStatus);
                }

                return(new BaseResponse()
                {
                    Message = $"Updated/Added status: {status.Status}"
                });
            }
            catch (Exception ex)
            {
                return(new BaseResponse()
                {
                    Error = ErrorCode.InternalError,
                    Message = ex.Message
                });
            }
        }
        private void AddProperties(DeviceDataFlag flag, List <Tuple <string, string> > properties)
        {
            //TODO: HIGH AddOrUpdate property
            switch (flag)
            {
            case DeviceDataFlag.Statusai:
                var statuses = new List <DetailedStatus>();
                foreach (var statusItem in properties)
                {
                    var stat = new DetailedStatus()
                    {
                        Status      = statusItem.Item1,
                        Description = statusItem.Item2,
                    };
                    statuses.Add(stat);
                }
                _statusService.AddOrUpdate(statuses);
                break;

            case DeviceDataFlag.klasifikatorius:
                var models = new List <DeviceModel>();
                foreach (var statusItem in properties)
                {
                    var deviceModel = new DeviceModel()
                    {
                        Name        = statusItem.Item1,
                        Description = statusItem.Item2,
                    };
                    models.Add(deviceModel);
                }
                _deviceModelService.AddOrUpdate(models);
                break;

            case DeviceDataFlag.komplektacijos:
                var groups = new List <Classification>();
                foreach (var groupItem in properties)
                {
                    var group = new Classification()
                    {
                        Code  = groupItem.Item1,
                        Model = groupItem.Item2,
                    };
                    groups.Add(group);
                }
                _groupService.AddOrUpdate(groups);
                break;

            case DeviceDataFlag.Vietos:
                var locations = new List <DeviceLocation>();
                foreach (var locationItem in properties)
                {
                    var location = new DeviceLocation()
                    {
                        Name    = locationItem.Item1,
                        Details = locationItem.Item2,
                    };
                    locations.Add(location);
                }
                _deviceLocationService.AddOrUpdate(locations);
                break;
            }
        }