Example #1
0
        public OperationResult <Guid?> CreateDevice(DeviceEditDto dto)
        {
            //Validazione argomenti
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            //Dichiaro la lista di risultati di ritorno
            IList <ValidationResult> vResults = new List <ValidationResult>();

            //Definisco l'entità
            Device entity = new Device();

            entity.Name       = dto.Name;
            entity.Macaddress = dto.Macaddress;
            entity.IsEnabled  = !dto.IsEnabled.HasValue ? false : dto.IsEnabled;

            //Eseguo la validazione logica
            vResults = ValidateEntity(entity);

            if (!vResults.Any())
            {
                //Salvataggio su db
                _deviceRepository.Save(entity);
            }

            //Ritorno i risultati
            return(new OperationResult <Guid?>
            {
                ReturnedValue = entity.Id,
                ValidationResults = vResults
            });
        }
Example #2
0
        protected virtual async Task <DeviceEditDto> CreateDeviceAsync(DeviceEditDto input)
        {
            var entity = ObjectMapper.Map <Device>(input);

            entity = await _deviceRepository.InsertAsync(entity);

            return(entity.MapTo <DeviceEditDto>());
        }
Example #3
0
        protected virtual async Task UpdateDeviceAsync(DeviceEditDto input)
        {
            var entity = await _deviceRepository.GetAsync(input.Id.Value);

            input.MapTo(entity);

            // ObjectMapper.Map(input, entity);
            await _deviceRepository.UpdateAsync(entity);
        }
Example #4
0
        public IHttpActionResult Update(DeviceEditDto dto)
        {
            //Recupero l'entity
            var oResult = _deviceService.UpdateDevice(dto);

            //Se ci sono stati errori, li notifico
            if (oResult.HasErrors())
            {
                Log4NetConfig.ApplicationLog.Warn(string.Format("Errore durante la modifica di un dispositivo. Nome: {0}, Macaddress: {1}",
                                                                dto.Name, dto.Macaddress, oResult.GetValidationErrorsInline(" - ")));
                NHibernateHelper.SessionFactory.GetCurrentSession().Transaction.Rollback();
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, oResult)));
            }

            //Ritorno i risultati
            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK)));
        }
        /// <summary>
        /// 通过Id获取设备信息进行编辑或修改
        /// Id为空时返回新对象
        /// </summary>
        public async Task <DeviceForEdit> GetForEditAsync(NullableIdDto <long> input)
        {
            DeviceEditDto deviceEditDto;

            if (input.Id.HasValue)
            {
                var entity = await _deviceRepository.GetAsync(input.Id.Value);

                deviceEditDto = entity.MapTo <DeviceEditDto>();
            }
            else
            {
                deviceEditDto = new DeviceEditDto();
            }
            return(new DeviceForEdit {
                DeviceEditDto = deviceEditDto
            });
        }
Example #6
0
        /// <summary>
        /// 导出Device为excel表
        /// </summary>
        /// <returns></returns>
        //public async Task<FileDto> GetDevicesToExcel(){
        //var users = await UserManager.Users.ToListAsync();
        //var userListDtos = ObjectMapper.Map<List<UserListDto>>(users);
        //await FillRoleNames(userListDtos);
        //return _userListExcelExporter.ExportToFile(userListDtos);
        //}
        /// <summary>
        /// MPA版本才会用到的方法
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <GetDeviceForEditOutput> GetDeviceForEdit(NullableIdDto <int> input)
        {
            var           output = new GetDeviceForEditOutput();
            DeviceEditDto deviceEditDto;

            if (input.Id.HasValue)
            {
                var entity = await _deviceRepository.GetAsync(input.Id.Value);

                deviceEditDto = entity.MapTo <DeviceEditDto>();

                //deviceEditDto = ObjectMapper.Map<List <deviceEditDto>>(entity);
            }
            else
            {
                deviceEditDto = new DeviceEditDto();
            }

            output.Device = deviceEditDto;
            return(output);
        }