Beispiel #1
0
        public IActionResult Create()
        {
            var viewModel = new CreatePropertyInputModel
            {
                TypeOfPropertiesItems = this.typeOfPropertiesService.GetAllKeyValuePairs(),
            };

            return(this.View(viewModel));
        }
        public async Task AddPropertiesShouldWorkCorrectly()
        {
            var db       = GetDatabase();
            var property = new CreatePropertyInputModel()
            {
                Name = "Name",
            };
            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);

            await db.SaveChangesAsync();

            Assert.Equal(1, db.Properties.Count());
        }
        public async Task CreateAsync(CreatePropertyInputModel input, string userId, string imagePath)
        {
            var property = new Property
            {
                TypeOfPropertyId = input.TypeOfPropertyId,
                Name             = input.Name,
                Description      = input.Description,
                Location         = input.Location,
                Price            = input.Price,
                Area             = input.Area,
                Baths            = input.Baths,
                Beds             = input.Beds,
                Garages          = input.Garages,
                AddedByUserId    = userId,
                Address          = input.Address,
            };

            var allowedExtensions = new[] { "jpg", "png", "gif" };

            Directory.CreateDirectory($"{imagePath}/properties");

            foreach (var image in input.Images)
            {
                var extension = Path.GetExtension(image.FileName).TrimStart('.');

                if (!allowedExtensions.Any(x => extension.EndsWith(x)))
                {
                    throw new Exception($"Invalid Image Extension {extension}");
                }

                var dbImage = new Image
                {
                    AddedByUserid = userId,
                    Extension     = extension,
                };
                property.Images.Add(dbImage);

                var phycicalPath = $"{imagePath}/properties/{dbImage.Id}.{extension}";

                using Stream fileStream = new FileStream(phycicalPath, FileMode.Create);
                await image.CopyToAsync(fileStream);
            }

            await this.propertiesRepository.AddAsync(property);

            await this.propertiesRepository.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task <IActionResult> Create(CreatePropertyInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.TypeOfPropertiesItems = this.typeOfPropertiesService.GetAllKeyValuePairs();
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            try
            {
                await this.propertiesService.CreateAsync(input, user.Id, $"{this.environment.WebRootPath}/images");
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                input.TypeOfPropertiesItems = this.typeOfPropertiesService.GetAllKeyValuePairs();
                return(this.View(input));
            }

            return(this.Redirect("/"));
        }
Beispiel #5
0
        public ResponseWrapper <CreatePropertyModel> CreateProperty(CreatePropertyInputModel model)
        {
            var newEntity = new Property
            {
                Name         = model.Name,
                PropertyType = model.PropertyType,
                EntityId     = model.EntityId,
            };

            context
            .Properties
            .Add(newEntity);

            context.SaveChanges();
            var response = new CreatePropertyModel
            {
                PropertyId   = newEntity.PropertyId,
                Name         = newEntity.Name,
                PropertyType = newEntity.PropertyType,
                EntityId     = newEntity.EntityId,
            };

            return(new ResponseWrapper <CreatePropertyModel>(_validationDictionary, response));
        }
        public dynamic CreateProperty([FromBody] CreatePropertyInputModel model)
        {
            var orchestrator = new PropertyOrchestrator(new ModelStateWrapper(this.ModelState));

            return(orchestrator.CreateProperty(model).GetResponse());
        }