public ActionResult CreditTypeEdit(AdminEditExchangeModel model)
        {
            if (ModelState.IsValid)
            {
                var api = GoPlayApi.Instance;
                var existingCredit = api.GetCreditType(model.string_identifier).Data;
                if (existingCredit != null && existingCredit.id != model.id)
                {
                    ModelState.AddModelError("string_identifier", Resources.Resources.STRING_IDENTIFIER_DUPLICATE);
                    return View("Edit", model);
                }

                var creditType = api.GetCreditType(model.id).Data;
                creditType = EditCreditType(creditType, model);
                if (api.UpdateCreditType(creditType))
                {
                    this.Flash(string.Format("Successfully updated credit type {0}!", model.name), FlashLevel.Success);
                    return RedirectToAction("CreditTypeDetail", model.id);
                }
                this.Flash(ErrorCodes.ServerError.ToErrorMessage(), FlashLevel.Error);
            }
            model.games = GameHelper.GetGamesForAdminUser(CurrentUser);
            return View("Edit", model);
        }
        public ActionResult PackageAdd(AdminEditExchangeModel model)
        {
            if (ModelState.IsValid)
            {
                var game = GameHelper.GetGameForCurrentUser(CurrentUser, model.game_id);
                var api = GoPlayApi.Instance;

                if (!PermissionHelper.HasManageStudio(CurrentUser.GetRoles(), CurrentUser.Id, game.studio_id ?? 0))
                {
                    return new HttpStatusCodeResult(403);
                }

                if (api.GetCreditType(model.string_identifier).Data != null)
                {
                    ModelState.AddModelError("string_identifier", Resources.Resources.STRING_IDENTIFIER_DUPLICATE);
                    return View("Edit", model);
                }

                Package package = new Package();
                package = EditPackage(package, model);
                int newId = api.CreatePackage(package);
                if (newId > 0)
                {
                    this.Flash(string.Format("Successfully added Package {0}!", model.name), FlashLevel.Success);
                    return RedirectToAction("PackageDetail", "exchange", new { id = newId });
                }

                this.Flash(string.Format(ErrorCodes.ServerError.ToErrorMessage(), model.name), FlashLevel.Error);
                return View("Edit", model);
            }
            return View("Edit", model);
        }
        private Package EditPackage(Package package, AdminEditExchangeModel model)
        {
            if (model.icon != null && model.icon.ContentLength > 0)
            {
                string path = HttpContext.Server.MapPath(ConfigurationManager.AppSettings["UPLOADS_DIR"]);
                string filename = GoPlayApi.Instance.HandleFile(HttpContext.Server.MapPath("~"), model.icon.InputStream, path, model.icon.FileName);
                package.icon_filename = filename;
            }

            package.is_active = (!string.IsNullOrEmpty(model.is_active) && model.is_active == "on")
                ? true
                : false;
            package.is_archived = (!string.IsNullOrEmpty(model.is_archived) && model.is_archived == "on")
                ? true
                : false;
            package.updated_at = DateTime.UtcNow;
            package.play_token_value = model.play_token_value;
            package.free_play_token_value = model.free_play_token_value;
            package.game_id = model.game_id;
            package.name = model.name;
            package.string_identifier = model.string_identifier;
            package.limited_time_offer = model.limited_time_offer;

            return package;
        }
        private CreditType EditCreditType(CreditType creditType, AdminEditExchangeModel model)
        {
            if (model.icon != null && model.icon.ContentLength > 0)
            {
                string path = HttpContext.Server.MapPath(ConfigurationManager.AppSettings["UPLOADS_DIR"]);
                string filename = GoPlayApi.Instance.HandleFile(HttpContext.Server.MapPath("~"), model.icon.InputStream, path, model.icon.FileName);
                creditType.icon_filename = filename;
            }

            creditType.is_active = (!String.IsNullOrEmpty(model.is_active) && model.is_active == "on")
                ? true
                : false;
            creditType.is_archived = (!string.IsNullOrEmpty(model.is_archived) && model.is_archived == "on")
                ? true
                : false;
            creditType.updated_at = DateTime.UtcNow;
            creditType.exchange_rate = model.exchange_rate;
            creditType.free_exchange_rate = model.free_exchange_rate;
            creditType.game_id = model.game_id;
            creditType.name = model.name;
            creditType.string_identifier = model.string_identifier;

            return creditType;
        }