public IActionResult Promotion(APromotion promotion) { Models.Promotion pro = new Models.Promotion(); pro = promotion.editedPromotion; if (ModelState.IsValid) { if (pro != null) { if (promotion.editedPromotion.id == 0) { db.Promotion.Add(pro); } else { Models.Promotion pd = db.Promotion.FirstOrDefault(); db.Entry(pd).State = Microsoft.EntityFrameworkCore.EntityState.Detached; db.SaveChanges(); db.Promotion.Update(pro); } } } db.SaveChanges(); updatePromotionList(1, "", "", 1); ModelState.Clear(); // ViewBag.pName = aProduct.editedProduct.name; // ViewBag.Id=aProduct.editedProduct.id; ViewBag.isCreation = "Create"; ViewBag.totalPage = Math.Ceiling(this.aPromotion.promotions.Count() / (double)proPageSize); return(View(this.aPromotion)); }
public Models.Promotion GetPromotion() { var promotion = new Models.Promotion(); promotion.Criterias = new List <string>() { "3 of A's for 130", "2 of B's for 45", "C & D for 30" }; return(promotion); }
public IActionResult Post([FromBody] Models.Promotion promotion) { if (promotion == null) { return(BadRequest()); } var prom = this._mapper.Map <Entities.Promotion>(promotion); prom.CreatedIP = "1.1.1.1"; var result = this._promotionsRepository.Insert(prom); if (result != null) { return(Created("api/promotions", result.Id)); } else { return(BadRequest("Failed to create promotion.")); } }
public IActionResult Put(string id, [FromBody] Models.Promotion promotion) { if (promotion == null) { return(BadRequest()); } var prom = this._mapper.Map <Entities.Promotion>(promotion); prom.ModifiedIP = "2.2.2.2"; var result = this._promotionsRepository.Update(id, prom); if (result) { var item = this._promotionsRepository.Find(id); return(Ok(item)); } else { return(BadRequest("Failed to Update promotion.")); } }