public CreateEntityCommandResult Handle(CreateLightCommand command) { CreateEntityCommandResult result = new CreateEntityCommandResult(); ObjectId roomId; if (!ObjectId.TryParse(command.RoomId, out roomId)) { AddNotification(nameof(roomId), ENotifications.InvalidFormat); } if (Valid) { PinPort pinPort = new PinPort(command.PinPort); Light light = new Light(command.Description, pinPort, roomId); if (light.Valid) { if (_roomRepository.Get(roomId) == null) { AddNotification(nameof(command.RoomId), ENotifications.NotFound); } if (Valid) { _lightRepository.Create(light); if (_lightRepository.Valid) { result = new CreateEntityCommandResult(HttpStatusCode.OK).Build <Light, CreateEntityCommandResult>(light); } } else { result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications); } } else { result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, light.Notifications); } } else { result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }
public IActionResult Create(Light light) { light.house = houseRepository.GetById(light.house.id); lightRepository.Create(light); return(RedirectToAction("Index")); }
public IActionResult Create(Light light) { repository.Create(light); return(RedirectToAction("Index")); }