Beispiel #1
0
        public SwitchViewModel UpdateSwitch(string userId, SwitchViewModel model)
        {
            if (model.Id == null)
            {
                throw new LynexException("Switch id is null");
            }

            var @switch = _switchRepository.Get(model.Id);

            if (@switch == null)
            {
                throw new LynexException(string.Format("Switch {0} does not exist", model.Id));
            }

            @switch.Name            = model.Name;
            @switch.Type            = model.Type;
            @switch.IconId          = model.IconId;
            @switch.ChipId          = model.ChipId;
            @switch.UpdatedDateTime = DateTime.UtcNow;
            _switchRepository.Update(@switch);
            _switchRepository.Save();

            model = new SwitchViewModel(@switch);

            return(model);
        }
        public DtoEditSwitch EditSwitch(DtoEditSwitch _switch)
        {
            var dbSwitch = switchRepository.Update(new Switch()
            {
                Id   = _switch.Id,
                Name = _switch.Name,
                Ip   = _switch.Ip,
                Mac  = _switch.Mac
            });

            if (dbSwitch == null)
            {
                return(null);
            }

            return(new DtoEditSwitch()
            {
                Id = _switch.Id,
                Name = _switch.Name,
                Ip = _switch.Ip,
                Mac = _switch.Mac
            });
        }