protected void BtnOrder_Click(object sender, EventArgs e) { OfferedPizza offerPizza = HelperSession.GetOfferPizza(Session); List <Ingredient> listIngredientsSelected = HelperSession.GetListIngredientsSelected(Session); OrderPizza orderPizza = new OrderPizza(offerPizza.Id_Offered_Pizza, offerPizza.Price, listIngredientsSelected); List <OrderPizza> listOrdersPizza = HelperSession.GetListOrdersPizza(Session); listOrdersPizza.Add(orderPizza); HelperSession.SetListOrdersPizza(Session, listOrdersPizza); double partialSum = HelperSession.GetSumOrderedPizzas(Session); partialSum += orderPizza.Price; HelperSession.SetSumOrderedPizzas(Session, partialSum); double totalSum = Properties.Settings.Default.PriceDeliveryAndService + partialSum; HelperSession.SetTotalPriceOrderedPizzas(Session, totalSum); Response.Redirect("Basket.aspx"); }
public IHttpActionResult Get(int id) { OfferedPizza offeredPizza = db.OfferedPizzas.Find(id); if (offeredPizza == null) { return(BadRequest("Unknown id.")); } return(Ok(offeredPizza)); }
protected void BtnOfferDetails_Click(object sender, EventArgs e) { Button btnOfferDetails = (Button)sender; int index = Convert.ToInt32(btnOfferDetails.CommandArgument.ToString()); List <OfferedPizza> listOffersPizza = Helper.HelperSession.GetListOffersPizza(Session); OfferedPizza offer = listOffersPizza[index]; Helper.HelperSession.SetOfferPizza(Session, offer); Response.Redirect("OfferDetails.aspx"); }
public async Task <IHttpActionResult> Delete(int id) { OfferedPizza offeredPizza = await db.OfferedPizzas.FindAsync(id); if (offeredPizza == null) { return(BadRequest("Unknown id.")); } db.OfferedPizzas.Remove(offeredPizza); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { return(BadRequest(e.Message)); } return(StatusCode(HttpStatusCode.NoContent)); }
protected void CbStatus_CheckedChanged(object sender, EventArgs e) { OfferedPizza offerPizza = HelperSession.GetOfferPizza(Session); List <Ingredient> listIngredientsOffer = HelperSession.GetListIngredientsOffer(Session); List <Ingredient> listIngredientsSelected = HelperSession.GetListIngredientsSelected(Session); CheckBox cbStatus = (CheckBox)sender; GridViewRow row = (GridViewRow)cbStatus.NamingContainer; if (row != null) { int index = row.RowIndex; Ingredient ingredient = listIngredientsOffer[index]; ingredient.Status = !(ingredient.Status); if (ingredient.Status) { offerPizza.Price += ingredient.Price; listIngredientsSelected.Add(ingredient); } else { offerPizza.Price -= ingredient.Price; listIngredientsSelected.Remove(ingredient); } listIngredientsOffer[index] = ingredient; LbPrice.Text = offerPizza.Price.ToString("0.00") + ""; HelperSession.SetListIngredientsOffer(Session, listIngredientsOffer); HelperSession.SetListIngredientsSelected(Session, listIngredientsSelected); HelperSession.SetOfferPizza(Session, offerPizza); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!IsPostBack) { OfferedPizza offerPizza = HelperSession.GetOfferPizza(Session); List <Ingredient> listIngredientsAll = HelperSession.GetListIngredientsAll(Session); List <Ingredient> listIngredientsOffer = HelperIngredient.Connect(offerPizza.Ingredients, listIngredientsAll); HelperSession.SetListIngredientsOffer(Session, listIngredientsOffer); GvListIngredients.DataSource = listIngredientsOffer; GvListIngredients.DataBind(); LbTitle.Text = offerPizza.Name; LbPrice.Text = offerPizza.Price.ToString("0.00") + ""; HelperSession.SetListIngredientsSelected(Session, offerPizza.Ingredients); } } }
public async Task <IHttpActionResult> Delete(int id) { Ingredient ingredient = await db.Ingredients.FindAsync(id); if (ingredient == null) { return(BadRequest("Unknown id.")); } var distinctedListOfOfferedPizzaIds = db.IngredientsOfOfferedPizza. Where(k => k.Id_Ingredient == ingredient.Id_Ingredient). Select(k => k.Id_Offered_Pizza). Distinct().ToList(); db.Ingredients.Remove(ingredient); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { return(BadRequest(e.Message)); } if (distinctedListOfOfferedPizzaIds != null) { foreach (var offeredPizzaId in distinctedListOfOfferedPizzaIds) { OfferedPizza offeredPizza = db.OfferedPizzas.Find(offeredPizzaId); if (offeredPizza == null) { continue; } var newIngredientsIds = db.IngredientsOfOfferedPizza. Where(k => k.Id_Offered_Pizza == offeredPizzaId). Select(k => k.Id_Ingredient). ToList(); decimal price = basicPrice; foreach (var newIngredientId in newIngredientsIds) { var existedIngredients = db.Ingredients.Find(newIngredientId); if (existedIngredients == null) { continue; } price += existedIngredients.Price; } offeredPizza.Price = price; } } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { return(BadRequest(e.Message)); } return(StatusCode(HttpStatusCode.NoContent)); }
public static void SetOfferPizza(HttpSessionState session, OfferedPizza offer) { session[SessionConstans.OfferPizza] = offer; }