Exemplo n.º 1
0
        public CommandResult Handle(UpdateLightCommand command)
        {
            CommandResult result = new CommandResult();

            ObjectId lightId = new ObjectId();

            if (!ObjectId.TryParse(command.LightId, out lightId))
            {
                AddNotification(nameof(command.LightId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Light light = _lightRepository.Get(lightId);

                if (light == null && _lightRepository.Valid)
                {
                    AddNotification(nameof(command.LightId), ENotifications.NotFound);
                }

                if (Valid)
                {
                    PinPort pinPort = null;

                    if (command.PinPort != null)
                    {
                        pinPort = new PinPort(command.PinPort);
                    }

                    light.Update(command.Description, pinPort);

                    if (light.Valid)
                    {
                        _lightRepository.Update(light);

                        if (_lightRepository.Valid)
                        {
                            result = new CommandResult(HttpStatusCode.OK);
                        }
                    }

                    else
                    {
                        result = new CommandResult(HttpStatusCode.BadRequest, light.Notifications);
                    }
                }

                else
                {
                    result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
                }
            }

            else
            {
                result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
Exemplo n.º 2
0
        public IActionResult Edit(EditLightViewModel model)
        {
            if (ModelState.IsValid)
            {
                Light light = _lightRepository.GetLightById(model.Id);
                light.Name    = model.Name;
                light.Iswell  = model.Iswell;
                light.Iswork  = model.Iswork;
                light.Lng     = model.Lng;
                light.Lat     = model.Lat;
                light.Sens    = model.Sens;
                light.Celle   = model.Celle;
                light.Control = model.Control;

                if (model.Photos.Count > 0)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }

                    light.PhotoPath = ProcessUpLoadedFile(model);
                }

                Light updatelight = _lightRepository.Update(light);
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 3
0
 public IActionResult Edit(Light light)
 {
     light.house = houseRepository.GetById(light.house.id);
     lightRepository.Update(light);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 4
0
 public IActionResult Edit(Light light)
 {
     repository.Update(light);
     return(RedirectToAction("Index"));
 }