Ejemplo n.º 1
0
        public async Task <IActionResult> Create(Guid societyId, Guid buildingId, [FromBody] FlatCreate flat)
        {
            if (flat == null)
            {
                return(BadRequest());
            }
            var exists = await this._societyService.IsBuildingExistsAsync(societyId, buildingId);

            if (!exists)
            {
                return(NotFound());
            }
            flat.CreatedBy   = this.LoggedInUserId;
            flat.CreatedDate = DateTime.UtcNow;
            flat.UpdatedBy   = this.LoggedInUserId;
            flat.UpdatedDate = DateTime.UtcNow;
            var response = await this._flatService.CreateFlat(societyId, buildingId, flat);

            if (response.Successful)
            {
                // return Ok(response.Data);
                return(CreatedAtRoute("GetFlatInSocietyBuilding",
                                      new { societyId = societyId, buildingId = buildingId, id = response.Data.Id },
                                      response.Data));
            }

            return(BadRequest(response.ErrorMessages));
        }
Ejemplo n.º 2
0
        public async Task <ServiceResponse <Flat> > CreateFlat(Guid societyId, Guid buildingId, FlatCreate flat)
        {
            var validator = new FlatCreateValidator();
            var results   = validator.Validate(flat);
            var response  = new ServiceResponse <Flat>();

            response.ErrorMessages = results.Errors.ToList();
            if (!response.Successful)
            {
                return(response);
            }
            var flatEntity = AutoMapper.Mapper.Map <Apollo.Domain.Entity.Society.Flat>(flat);

            flatEntity.Id         = Guid.NewGuid();
            flatEntity.SocietyId  = societyId;
            flatEntity.BuildingId = buildingId;
            var result = await this._flatRepository.AddAsync(flatEntity);

            response.Data = AutoMapper.Mapper.Map <Apollo.Domain.DTO.Society.Flat>(result);
            return(response);
        }