public IActionResult Details(int id) { var sensor = sensorService.GetSensorById(id); var sensorViewModel = new SensorDetailsViewModel(sensor); return(View(sensorViewModel)); }
public void GetSensorById_WhenSensorExists() { // Arrange var sensor = fixture.Create <Sensor>(); repository.Setup(r => r.GetById(sensor.snID)) .Returns(sensor); unitOfWork.Setup(r => r.GetRepository()). Returns(repository.Object); // Act var result = sensorService.GetSensorById(sensor.snID); // Assert Assert.Equal(sensor, result); }
public IActionResult GetSensors(long id) { return(Ok(sensorService.GetSensorById(id))); }
public async Task <JsonResult> GetAllOrdersForAdmin(CheckModel model) { var results = new List <ValidationResult>(); var context = new ValidationContext(model); if (!Validator.TryValidateObject(model, context, results, true)) { return(Json("Bad data")); } ApplicationUserDTO checkUser = new ApplicationUserDTO { Email = model.Email, SecurityStamp = model.SecurityStamp }; try { ApplicationUserDTO user = await userService.GetUserByEmailAndSecurityStamp(checkUser); if (user.Role != "admin") { return(Json("Only Admin can get orders")); } else { List <GetEmptyOrder> orders = new List <GetEmptyOrder>(); List <OrderDTO> ordersDTO = orderService.GetOrdersWithoutCourier().ToList(); foreach (var orderDTO in ordersDTO) { SensorDTO sensor; try { sensor = sensorService.GetSensorById(orderDTO.SensorId); } catch { return(Json("Bad with get sensor")); } MonitoringDTO monitoringDTo; try { monitoringDTo = monitoringService.GetMonitoringsBySensorId(sensor.Id); } catch { return(Json("Bad with get monitoring")); } ApplicationUserDTO customerUser; try { customerUser = await userService.GetUserById(monitoringDTo.ApplicationUserId); } catch { return(Json("Bad with get user")); } ProductDTO productDTO; try { productDTO = productService.GetProductById(sensor.ProductId); } catch { return(Json("Bad with get product")); } GetEmptyOrder order = new GetEmptyOrder { CountProduct = sensor.CountProduct, CustomerEmail = customerUser.Email, DeliveryAddress = orderDTO.DeliveryAddress, Price = orderDTO.Price, ProductName = productDTO.Name, Id = orderDTO.Id }; orders.Add(order); } return(Json(orders, JsonRequestBehavior.AllowGet)); } } catch { return(Json("Email or Token is wrong")); } }
public async Task <JsonResult> GetMonitoringsByUserEmailAndSecurityStamp(CheckModel model) { var results = new List <ValidationResult>(); var context = new ValidationContext(model); if (!Validator.TryValidateObject(model, context, results, true)) { return(Json("Bad data")); } ApplicationUserDTO checkUser = new ApplicationUserDTO { Email = model.Email, SecurityStamp = model.SecurityStamp }; try { ApplicationUserDTO user = await userService.GetUserByEmailAndSecurityStamp(checkUser); if (user.Role != "user") { return(Json("Only User can monitoring", JsonRequestBehavior.AllowGet)); } else { try { var monitorngs = monitoringService.GetMonitoringsByUserId(user.Id).ToList(); List <GetSensor> getSensors = new List <GetSensor>(); foreach (var monitoring in monitorngs) { try { SensorDTO sensor = sensorService.GetSensorById(monitoring.SensorId); try { ApplicationUserDTO ownerUser = await userService.GetUserById(sensor.ApplicationUserId); try { var mapper = new AutoMapper.MapperConfiguration(cfg => cfg.CreateMap <SensorDTO, GetSensor>()).CreateMapper(); GetSensor getSensor = mapper.Map <SensorDTO, GetSensor>(sensor); ProductDTO product = productService.GetProductById(sensor.ProductId); getSensor.ProductName = product.Name; getSensor.ObserverEmail = ownerUser.Email; getSensors.Add(getSensor); } catch { return(Json("Bad with get product", JsonRequestBehavior.AllowGet)); } } catch { return(Json("Bad with get owner user", JsonRequestBehavior.AllowGet)); } } catch { return(Json("Bad with get sensor", JsonRequestBehavior.AllowGet)); } } return(Json(getSensors, JsonRequestBehavior.AllowGet)); } catch { return(Json("Bad with monitorings", JsonRequestBehavior.AllowGet)); } } } catch { return(Json("Email or Token is wrong", JsonRequestBehavior.AllowGet)); } }
public JsonResult Details(int?id) { var sensor = sensorService.GetSensorById(id); return(Json(sensor, JsonRequestBehavior.AllowGet)); }
public Sensor Get(int id) { return(_sensorService.GetSensorById(id)); }