示例#1
0
        public IHttpActionResult Create([FromBody] HouseDto houseDto)
        {
            if (houseDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntity = _houseMapper.MapToEntity(houseDto);

            _houseRepository.Add(houseEntity);

            return(CreatedAtRoute("GetSingleHouse", new { id = houseEntity.Id }, _houseMapper.MapToDto(houseEntity)));
        }
示例#2
0
        public HttpResponseMessage AddHouse([FromBody] House house)
        {
            if (house == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            var response = Request.CreateResponse <House>(HttpStatusCode.Created, house);

            try
            {
                m_houseRepository.Add(house);
            }
            catch (DbEntityValidationException ex)
            {
                response.Content = new StringContent(GetErrorLog(ex));
            }
            response.Headers.Location = GetHouseLocation(house.HouseId);
            return(response);
        }
示例#3
0
        public IActionResult Create(HouseCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                //for file uploading
                string uniqueFileName = ProcessUploadedFile(model); //utility method for processing photo upload
                House  newHouse       = new House()                 //id is generated by ef core
                {
                    Address    = model.Address,
                    OwnerEmail = model.OwnerEmail,
                    Type       = model.Type,
                    Price      = model.Price,
                    PhotoPath  = uniqueFileName
                };

                _houseRepository.Add(newHouse);                                                              //this method generates id value
                return(RedirectToAction("details", new { id = protector.Protect(newHouse.Id.ToString()) })); //this statement redirects request to another action
            }

            return(View());//if ModelState is not valid view will render all errors
        }
示例#4
0
        public House CreateHouseForCitizen(Citizen citizen)
        {
            var house = new House()
            {
                CitizenID = citizen.ID,
                Condition = 100m,
                RegionID  = citizen.RegionID,
            };

            house.HouseFurnitures.Add(new HouseFurniture()
            {
                FurnitureTypeID = (int)FurnitureTypeEnum.Chest,
                Quality         = 1,
                HouseChest      = new HouseChest()
                {
                    Capacity = 20
                }
            });

            houseRepository.Add(house);
            ConditionalSaveChanges(houseRepository);

            return(house);
        }
示例#5
0
 public void AddAssetsHouse(HouseAttribute item)
 {
     _assetsHouseRep.Add(item);
 }
示例#6
0
 public House Add(House newHouse)
 {
     return(_houseRepository.Add(newHouse));
 }