public IHttpActionResult CreateOffer(OfferInputModel offerInput) { if (offerInput == null) { return this.BadRequest("Invalid Offer data"); } if (!this.ModelState.IsValid) { return this.BadRequest(ModelState); } var currentUserId = this.User.Identity.GetUserId(); var offer = new Offer() { Title = offerInput.Title, Description = offerInput.Description, Price = offerInput.InitialPrice, ExppirationDate = offerInput.ExpirationDate, PublishedOn = DateTime.Now, UserSellerId = currentUserId }; this.Data.Offers.Add(offer); this.Data.SaveChanges(); return this.CreatedAtRoute( "DefaultApi", new { id = offer.Id }, new { offer.Id, Seller = this.User.Identity.GetUserName(), Message = "Offer created" } ); }
public IHttpActionResult PostOffer(OfferInputModel offerData) { if (!ModelState.IsValid || offerData == null) { return(this.BadRequest(ModelState)); } var currentUserId = this.User.Identity.GetUserId(); if (currentUserId == null) { return(this.Unauthorized()); } var offer = new Offer() { Title = offerData.Title, Description = offerData.Description, InitialPrice = offerData.InitialPrice, ExpirationDate = offerData.ExpirationDateTime, PublishDate = DateTime.Now, SellerId = currentUserId }; this.db.Offers.Add(offer); this.db.SaveChanges(); var currentUserName = User.Identity.GetUserName(); return(this.CreatedAtRoute( "PostOffer", new { id = offer.Id }, new { id = offer.Id, Seller = currentUserName, Message = "Offer created." })); }
public IActionResult Index() { var model = new OfferInputModel(); model.Cities = this.homeService.GetCities(); return(View(model)); }
public void CreateShipmentAddNewShipmentToDataBase() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("nameOfDatabase"); var db = new ApplicationDbContext(optionsBuilder.Options); var input = new OfferInputModel() { From = 1, To = 17, CountOfPallets = 3, Length = 1.74, Width = 2, Height = 2, Weight = 500, IsExpressDelivery = true, IsFragile = true }; var homeService = new HomeService(db); homeService.CreateShipment(input); int result = db.Shipments.Count(); Assert.Equal(1, result); }
public IActionResult GenerateOffer([FromBody] OfferInputModel offer) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(_offerAppService.GeneratorOffer(offer))); }
/// <summary> /// Generate Offer /// </summary> /// <param name="offer"></param> /// <returns></returns> public ResponseViewModel GeneratorOffer(OfferInputModel offer) { var data = _mapper.Map <OfferInputModel, Offer>(offer); var mapped = _offerService.GenerateOffer(data); var result = _mapper.Map <Offer, OfferViewModel>(mapped); return(Ok(result)); }
public IActionResult Index(OfferInputModel input) { if (!ModelState.IsValid) { input.Cities = this.homeService.GetCities(); return(this.View(input)); } if (input.From == input.To) { return(this.Redirect($"/Offers/ShipmentInSameCity?cityName={input.From}")); } string shipmentId = this.homeService.CreateShipment(input); return(this.RedirectToAction("Calculate", "Offers", new { ShipmentId = shipmentId })); }
public string CreateShipment(OfferInputModel input) { var currShipment = new Shipment() { FromCityId = input.From, ToCityId = input.To, CountOfPallets = input.CountOfPallets, Length = input.Length, Width = input.Width, Height = input.Height, Weight = input.Weight, IsExpressDelivery = input.IsExpressDelivery, IsFragile = input.IsFragile }; this.db.Shipments.Add(currShipment); this.db.SaveChanges(); return(currShipment.Id); }
public IActionResult MyTestView() { var viewModel = new OfferInputModel { Weight = 12, Height = 122, Length = 234, IsFragile = true, Width = 99, CountOfPallets = 33 }; var model = new TestViewModel() { CountOfPallets = 234, CategoryId = 3 }; return(this.View(model)); }
public IHttpActionResult CrateOffer(OfferInputModel offerData) { if (offerData == null) { return(BadRequest("Missing offer data.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUserId = User.Identity.GetUserId(); var seller = this.db.UserStore.FindByIdAsync(currentUserId).Result; if (seller == null) { return(this.Unauthorized()); } var offer = new Offer() { Title = offerData.Title, Description = offerData.Description, DatePublished = DateTime.Now, SellerId = currentUserId, InitialPrice = offerData.InitialPrice, ExpirationDateTime = offerData.ExpirationDateTime }; db.Offers.Add(offer); db.SaveChanges(); return(this.CreatedAtRoute("OfferDetails", new { id = offer.Id }, new { offer.Id, Seller = seller.UserName, Message = "Offer created." })); }