public JsonResult UpdateMyProfile(FormCollection fc) { var ReturnCode = new ReturnCodeObj() { StatusCode = (int)ErrorCodes.UnknownError, StatusMessage = String.Empty }; try { DateTime registDt = DateTime.Now; Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]); var field_names = new string[] { "phone" }; bool isMissingRequiredFields = false; foreach (var x in tmpCollection) { if (!field_names.Contains(x.Key)) if (String.IsNullOrEmpty(x.Value)) { isMissingRequiredFields = true; break; } } if (!isMissingRequiredFields) // process form { string firstname = tmpCollection["firstname"]; string lastname = tmpCollection["lastname"]; string phone = string.Empty; if (!String.IsNullOrEmpty(fc["phone"])) phone = fc["phone"]; if (firstname.Length > 32) ReturnCode.StatusMessage = "First Name cannot exceed 32 characters."; if (lastname.Length > 32) ReturnCode.StatusMessage = "Last Name cannot exceed 32 characters."; if (!String.IsNullOrEmpty(ReturnCode.StatusMessage)) return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); if (User.Identity.IsAuthenticated) { var context = new IPTV2Entities(); var userId = new System.Guid(User.Identity.Name); var user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user != null) { user.FirstName = firstname; user.LastName = lastname; user.PhoneNumber = phone; if (context.SaveChanges() > 0) { //update userinfo in gigya SetGigyaAccountInfo(user); ReturnCode.StatusCode = (int)ErrorCodes.Success; ReturnCode.StatusMessage = "You have successfully updated your profile"; } } else ReturnCode.StatusMessage = "User does not exist."; } else ReturnCode.StatusMessage = "Your session has already expired. Please login again."; } else ReturnCode.StatusMessage = "Please fill in all required fields."; } catch (Exception e) { MyUtility.LogException(e); ReturnCode.StatusMessage = String.Format("Exception: {0} | Inner Exception: {1}", e.Message, e.InnerException.Message); } return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); }
public JsonResult VerifyPrepaidCard(FormCollection fc) { var ReturnCode = new ReturnCodeObj() { StatusCode = (int)ErrorCodes.UnknownError, StatusMessage = String.Empty }; try { DateTime registDt = DateTime.Now; Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]); bool isMissingRequiredFields = false; foreach (var x in tmpCollection) { if (String.IsNullOrEmpty(x.Value)) { isMissingRequiredFields = true; break; } } if (!isMissingRequiredFields) // process form { string serial = fc["serial"]; string pin = fc["pin"]; serial = serial.Replace(" ", String.Empty); pin = pin.Replace(" ", String.Empty); if (!Request.IsLocal) pin = MyUtility.GetSHA1(pin); // encrypt if (User.Identity.IsAuthenticated) { Ppc.ErrorCode code; var context = new IPTV2Entities(); System.Guid userId = new System.Guid(User.Identity.Name); User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user != null) { Offering offering = context.Offerings.Find(GlobalConfig.offeringId); if (user.HasPendingGomsChangeCountryTransaction(offering)) ReturnCode.StatusMessage = "We are processing your recent change in location. Please try again after a few minutes."; else { var ppc = context.Ppcs.FirstOrDefault(p => String.Compare(p.SerialNumber, serial, true) == 0); if (ppc != null) { if (!(String.Compare(ppc.SerialNumber, serial, true) == 0 && String.Compare(ppc.Pin, pin, false) == 0)) ReturnCode.StatusMessage = "Invalid serial/pin combination."; else if (ppc.ExpirationDate < registDt) ReturnCode.StatusMessage = "Prepaid Card/ePIN is already expired."; else if (ppc.UserId != null) ReturnCode.StatusMessage = "Prepaid Card/ePIN is already used."; else { if (ppc is ReloadPpc) { if (user.HasExceededMaximumReloadTransactionsForTheDay(GlobalConfig.reloadTransactionMaximumThreshold, registDt)) ReturnCode.StatusMessage = String.Format("You have exceeded the maximum number of transactions ({0}) allowed per day. Please try again later.", GlobalConfig.paymentTransactionMaximumThreshold); else // process reloadPpc { code = ReloadHelper.ReloadViaPrepaidCard(context, userId, serial, pin); if (code == Ppc.ErrorCode.Success) { var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, user.Country.CurrencyCode, true) == 0); ReturnCode.StatusCode = (int)ErrorCodes.Success; ReturnCode.StatusMessage = String.Format("You have successfully topped up your wallet. Your wallet balance is {0} {1}.", wallet.Currency, wallet.Balance); } else ReturnCode.StatusMessage = MyUtility.GetPpcErrorMessages(code); } } else if (ppc is SubscriptionPpc) { if (user.HasExceededMaximumPaymentTransactionsForTheDay(GlobalConfig.paymentTransactionMaximumThreshold, registDt)) ReturnCode.StatusMessage = String.Format("You have exceeded the maximum number of transactions ({0}) allowed per day. Please try again later.", GlobalConfig.paymentTransactionMaximumThreshold); else { SubscriptionPpc sPpc = (SubscriptionPpc)ppc; Product product = context.Products.FirstOrDefault(p => p.ProductId == sPpc.ProductId); if (product == null) ReturnCode.StatusMessage = "This product does not exist."; else { SubscriptionProductType subscriptionType = ContextHelper.GetProductType(product); TFCTV.Models.ErrorResponse response = PaymentHelper.PayViaPrepaidCard(context, userId, sPpc.ProductId, subscriptionType, serial, pin, userId, null); code = (Ppc.ErrorCode)response.Code; if (code == Ppc.ErrorCode.Success) { ReturnCode.StatusCode = (int)ErrorCodes.Success; ReturnCode.StatusMessage = String.Format("You have successfully subscribed to {0}.", product.Description); } else ReturnCode.StatusMessage = MyUtility.GetAirPlusPpcErrorMessages(code); } } } else ReturnCode.StatusMessage = "Unable to retrieve this type of Prepaid Card/ePIN."; } } else ReturnCode.StatusMessage = "Prepaid Card/ePIN does not exist."; } } else ReturnCode.StatusMessage = "User does not exist."; } else ReturnCode.StatusMessage = "Your session has already expired. Please login again."; } else ReturnCode.StatusMessage = "Please fill in all required fields."; } catch (Exception e) { MyUtility.LogException(e); ReturnCode.StatusMessage = String.Format("Exception: {0} | Inner Exception: {1}", e.Message, e.InnerException.Message); } return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); }