public CreateRealEstateResponseModel CreateEstate(RealEstateRequestModel estate, string userId) { var newEstate = new Estate() { Title = estate.Title, Description = estate.Description, Address = estate.Address, Contact = estate.Contact, ConstructionYear = estate.ConstructionYear, SellingPrice = estate.SellingPrice, RentingPrice = estate.RentingPrice, RealEstateType = (EstateType)estate.Type, CreatedOn = DateTime.UtcNow, CanBeRented = (estate.RentingPrice != null), CanBeSold = (estate.SellingPrice != null) }; var loggedUser = this.users .GetById(userId); loggedUser.Estates.Add(newEstate); this.users.SaveChanges(); var responseEstate = new CreateRealEstateResponseModel() { Id = newEstate.Id, Title = newEstate.Title, SellingPrice = newEstate.SellingPrice, RentingPrice = newEstate.RentingPrice, CanBeSold = newEstate.CanBeSold, CanBeRented = newEstate.CanBeRented }; return responseEstate; }
public IHttpActionResult Post(RealEstateRequestModel model) { var newRealEstate = Mapper.Map<RealEstate>(model); var id = this.realEstates.AddNew(newRealEstate, this.User.Identity.GetUserId()); var result = this.realEstates .GetById(id) .ProjectTo<ListedRealEstateResponseModel>() .FirstOrDefault(); return this.Created($"/api/RealEstates/{id}", result); }
public IHttpActionResult Post(RealEstateRequestModel model) { var newRealEstate = Mapper.Map <RealEstate>(model); var id = this.realEstates.AddNew(newRealEstate, this.User.Identity.GetUserId()); var result = this.realEstates .GetById(id) .ProjectTo <ListedRealEstateResponseModel>() .FirstOrDefault(); return(this.Created($"/api/RealEstates/{id}", result)); }
public IHttpActionResult Post(RealEstateRequestModel model) { var loggedUserId = this.User.Identity.GetUserId(); var createdEstate = this.estates.CreateEstate(model, loggedUserId); if (createdEstate != null) { return this.Created( string.Format("/api/RealEstates/{0}", createdEstate.Id), createdEstate); } return this.BadRequest(); }
public IHttpActionResult Post(RealEstateRequestModel request) { if (!this.ModelState.IsValid) { return(this.BadRequest("Invalid model")); } var estateId = this.realEstateServices.Add( request.Title, request.Description, request.Address, request.Contact, request.ConstructionYear, (int)request.Type); return(this.Created("api/RealEstates", estateId)); }
public IHttpActionResult Post(RealEstateRequestModel request) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model"); } var estateId = this.realEstateServices.Add( request.Title, request.Description, request.Address, request.Contact, request.ConstructionYear, (int)request.Type); return this.Created("api/RealEstates", estateId); }
public IHttpActionResult Post(RealEstateRequestModel model) { var userId = this.User.Identity.GetUserId(); var realEstate = new RealEstate() { Title = model.Title, Description = model.Description, Address = model.Address, Contact = model.Contact, ConstructionYear = model.ConstructionYear, SellingPrice = model.SellingPrice, RentingPrice = model.RentingPrice, RealEstateType = (RealEstateType)model.Type, CreatedOn = DateTime.UtcNow, UserId = userId }; this.data.RealEstates.Add(realEstate); this.data.SaveChanges(); var response = this.data.RealEstates.All() .Where(re => re.Id == realEstate.Id) .ProjectTo<RealEstateBaseResponseModel>() .FirstOrDefault(); return this.Created("api/RealEstates", response); }