public ActionResult Order(TransactionViewModel model) { if (ModelState.IsValid) { //var api = GoEat.Core.GoEatApi.Instance; //var discount = api.GetCurrentDiscount(model.customer_id, model.restaurant_id); //if (discount.Succeeded && !discount.Data.is_activated) //{ // model.cashier_id = CurrentUser.Id; // model.final_amount = model.price - (model.price * model.discount_percentage); // var transaction = new Transaction() // { // customer_id = model.customer_id, // restaurant_id = model.restaurant_id, // order_id = model.order_id, // price = model.price, // created_at = DateTime.Now, // discount_percentage = model.discount_percentage, // final_amount = model.final_amount, // cashier_id = model.cashier_id // }; // //create transaction // var rs = api.CreateTransaction(transaction); // if (rs.Succeeded) // { // //set status of user bardcode // api.UpdateUserDiscount(transaction.customer_id, discount.Data.id, false);//set false now for testing // } // //notifiy to user // NotifyUser(model.customer_id, "Your code have been activated successfully!"); // return RedirectToAction("Index"); //} } return View(model); }
public object CheckBarcode([FromBody] BarcodeToken param) { try { if (param == null) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } var tokenDecode = Cryptogahpy.Base64Decode(param.token); if (string.IsNullOrEmpty(tokenDecode) || tokenDecode.Split('-').Count() != 3) { return Json(new { success = false, error_code = ErrorCodes.InvalidBarCode.ToString() }); } var api = GoEatApi.Instance; string[] values = tokenDecode.Split('-'); int userId = Int32.Parse(values[1]); int restaurantId = Int32.Parse(values.First()); var discount = api.GetCurrentDiscount(userId, restaurantId).Data; if (discount != null && !discount.is_activated && discount.id == Int32.Parse(values.Last())) { var currentUser = api.GetUserById(userId); var model = new TransactionViewModel { customer_id = userId, nickname = currentUser.Data.Profile.nickname, restaurant_id = restaurantId, discount_percentage = discount.rate, rateTokenWithSGD = ConstantValues.D_RATE_TOKEN_SGD, service_charge = ConstantValues.D_SERVICE_CHARGE, gst = ConstantValues.D_GST, //TODO: consider if we need to call service to get exactly gtoken in this time or we get from DB simply token_balance = currentUser.Data.Profile.gtoken == null ? 0 : currentUser.Data.Profile.gtoken.Value, is_venvici_member = currentUser.Data.Profile.is_venvici_member, username = currentUser.Data.Profile.account }; return Json(new { success = true, order = model }); } return Json(new { success = false, error_code = ErrorCodes.InvalidBarCode.ToString() }); } catch { return Json(new { success = false, error_code = ErrorCodes.InvalidBarCode.ToString() }); } }
public ActionResult Order() { var token = Request.Params["token"]; var tokenDecode = Cryptogahpy.Base64Decode(token); if (!String.IsNullOrEmpty(tokenDecode)) { if (tokenDecode.Split('-').Count() != 3) { ModelState.AddModelError("CustomeError", "This code is invalid!"); return View(); } var api = GoEatApi.Instance; var userId = Int32.Parse(tokenDecode.Split('-')[1]); var restaurantId = Int32.Parse(tokenDecode.Split('-').First()); var discount = api.GetCurrentDiscount(userId, restaurantId); if (discount.Succeeded) { if (!discount.Data.is_activated) { if (discount.Data.id == Int32.Parse(tokenDecode.Split('-').Last())) { // code is valid and can create new transaction var model = new TransactionViewModel { customer_id = userId, nickname = api.GetUserById(userId).Data.Profile.nickname, restaurant_id = restaurantId, discount_percentage = discount.Data.rate }; return View(model); } ViewBag.CustomeError = "This code is invalid!"; } else { ViewBag.CustomeError = "This code was activated!"; } } else { ViewBag.CustomeError = "This code is invalid!"; } } return View(); }