Esempio n. 1
0
        public Result <string> AddFlat(AdminFlat adminFlat)
        {
            var flat = Mapper.Map <Flat>(adminFlat);

            flat.Pictures = _photoService.AddAdvertPhotos(adminFlat.Files);
            foreach (var photo in flat.Pictures)
            {
                photo.AdType = AdType.Flat;
                photo.Flat   = flat;
            }

            var result = _context.Flats.Add(flat);

            _context.SaveChanges();

            return(new Result <string>(true, null, "", String.Format("{0}{1}", flat.Id * 9999, "12")));
        }
        public Result UpdateFlat(EditFlat editFlat, int id)
        {
            var oldFlat = _applicationContext.Flats.Find(id);

            if (oldFlat != null)
            {
                if (editFlat.ToDeleted != null)
                {
                    foreach (var photoId in editFlat.ToDeleted)
                    {
                        oldFlat.Pictures.RemoveAll(x => x.Id == photoId);
                    }
                }
                var newPhotos = _photoService.AddAdvertPhotos(editFlat.Files);
                foreach (var photo in newPhotos)
                {
                    photo.AdType = AdType.Flat;
                    photo.Flat   = oldFlat;
                    oldFlat.Pictures.Add(photo);
                }
                oldFlat.Title              = editFlat.Title;
                oldFlat.Area               = editFlat.Area;
                oldFlat.City               = editFlat.City;
                oldFlat.Description        = editFlat.Description;
                oldFlat.Details            = editFlat.Details;
                oldFlat.Heating            = editFlat.Heating;
                oldFlat.Location           = editFlat.Location;
                oldFlat.Ownership          = editFlat.Ownership;
                oldFlat.Price              = editFlat.Price;
                oldFlat.PricePerMeter      = editFlat.PricePerMeter;
                oldFlat.Rent               = editFlat.Rent;
                oldFlat.Rooms              = editFlat.Rooms;
                oldFlat.Storey             = editFlat.Storey;
                oldFlat.ToLet              = editFlat.ToLet;
                oldFlat.TechnicalCondition = editFlat.TechnicalCondition;

                _applicationContext.SaveChanges();

                return(new Result(true, null, ""));
            }
            return(new Result(false, null, ""));
        }
        public List<UploadedPhoto> AddPhoto()
        {
            var encodedFiles = HttpContext.Current.Request.Files;
            var files = new List<HttpPostedFileBase>();
            if (encodedFiles != null && encodedFiles.Count > 0)
            {
                for (int i = 0; i < encodedFiles.Count; i++)
                {
                    var image = new HttpPostedFileWrapper(encodedFiles.Get(i));
                    files.Add(image);
                }
                var photos = _photoService.AddAdvertPhotos(files);

                return Mapper.Map<List<UploadedPhoto>>(photos);
            }
            return new List<UploadedPhoto>() { null };
        }