示例#1
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));
        }
示例#2
0
        public ViewResult Edit(int id)
        {
            Light light = _lightRepository.GetLightById(id);
            EditLightViewModel editLightViewModel = new EditLightViewModel
            {
                Id                = light.Id,
                Name              = light.Name,
                Iswell            = light.Iswell,
                Iswork            = light.Iswork,
                Lng               = light.Lng,
                Lat               = light.Lat,
                Control           = light.Control,
                Celle             = light.Celle,
                Sens              = light.Sens,
                ExistingPhotoPath = light.PhotoPath
            };

            return(View(editLightViewModel));
        }