コード例 #1
0
        public Result UpdateLand(EditLand editLand, int id)
        {
            var oldLand = _applicationContext.Lands.Find(id);

            if (oldLand != null)
            {
                if (editLand.ToDeleted != null)
                {
                    foreach (var photoId in editLand.ToDeleted)
                    {
                        oldLand.Pictures.RemoveAll(x => x.Id == photoId);
                    }
                }
                var newPhotos = _photoService.AddAdvertPhotos(editLand.Files);
                foreach (var photo in newPhotos)
                {
                    photo.AdType = AdType.Land;
                    photo.Land   = oldLand;
                    oldLand.Pictures.Add(photo);
                }
                oldLand.Title       = editLand.Title;
                oldLand.Area        = editLand.Area;
                oldLand.City        = editLand.City;
                oldLand.Description = editLand.Description;
                oldLand.Details     = editLand.Details;
                oldLand.Location    = editLand.Location;
                oldLand.Ownership   = editLand.Ownership;
                oldLand.Price       = editLand.Price;

                _applicationContext.SaveChanges();

                return(new Result(true, null, ""));
            }
            return(new Result(false, null, ""));
        }
コード例 #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult EditLand(EditLand editLand, int id)
        {
            editLand.Pictures = new List <Photo>();
            if (ModelState.IsValid)
            {
                _updateAdvertService.UpdateLand(editLand, id);
                return(RedirectToAction("Show", "Home", new { key = String.Format("{0}{1}", id * 9999, "18") }));
            }

            var land = _genericRepository.GetSet <Land>().FirstOrDefault(x => x.Id == id);

            if (land != null)
            {
                editLand.Pictures = land.Pictures;
            }
            return(View(editLand));
        }