コード例 #1
0
        public async Task <int> Create(PropertyCreateRequest request)
        {
            var property = new Property()
            {
                Title               = request.Title,
                ApartmentNumber     = request.ApartmentNumber,
                StreetNames         = request.StreetNames,
                WardId              = request.WardId,
                Area                = request.Area,
                AreaFrom            = request.AreaFrom,
                AreaTo              = request.AreaTo,
                Length              = request.Length,
                Width               = request.Width,
                Facade              = request.Facade,
                Price               = request.Price,
                PriceFrom           = request.PriceFrom,
                PriceTo             = request.PriceTo,
                Description         = request.Description,
                EvaluationStatusId  = request.EvaluationStatusId,
                LegalPapersId       = request.LegalPapersId,
                TypeOfPropertyId    = request.TypeOfPropertyId,
                TypeOfTransactionId = request.TypeOfTransactionId,
                StartDate           = DateTime.Now,
                EndDate             = request.EndDate,
                NumberOfStoreys     = request.NumberOfStoreys,
                NumberOfBedrooms    = request.NumberOfBedrooms,
                NumberOfWCs         = request.NumberOfWCs,
                HouseDirectionId    = request.HouseDirectionId,
                Lat          = request.Lat,
                Lng          = request.Lng,
                ContactName  = request.ContactName,
                EmailContact = request.EmailContact,
                ContactPhone = request.ContactPhone,
                UserID       = request.UserID,
            };

            if (request.ThumbnailImage != null)
            {
                property.PropertyImages = new List <PropertyImage>()
                {
                    new PropertyImage()
                    {
                        Caption     = "Thumbnail image",
                        DateCreated = DateTime.Now,
                        FileSize    = request.ThumbnailImage.Length,
                        LinkName    = await this.SaveFile(request.ThumbnailImage),
                        IsDefault   = true,
                        SortOrder   = 1
                    }
                };
            }
            _context.Properties.Add(property);
            await _context.SaveChangesAsync();

            return(property.Id);
        }
コード例 #2
0
        public async Task <IActionResult> Create([FromForm] PropertyCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string userId     = User.Claims.First(c => c.Type == "UserID").Value;
            var    propertyId = await _userService.Create(userId, request);

            if (propertyId == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
コード例 #3
0
        public async Task <IActionResult> Create(PropertyCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var propertyId = await _ownerPropertyService.Create(request);

            if (propertyId == 0)
            {
                return(BadRequest());
            }
            var property = await _ownerPropertyService.GetById(propertyId);

            return(CreatedAtAction(nameof(GetById), new { id = propertyId }, property));
        }