/// <summary> /// Получает все купленные неактивированные пользователем продуктов /// </summary> /// <param name="active">Статус активациии таблице user_chest (Не активный)</param> /// <param name="lang">Локаль для перевода описания и имени продукта</param> /// <returns>Список не активированных продуктов</returns> public IHttpActionResult GetChestInactiveItems(bool active = false, string lang = "EN") { string userId = User.Identity.GetUserId(); var result = new Dictionary <int, ChestFields>(); UserChest userChest = _getModel(); var chestItems = userChest.GetCountProductId(userId, active); foreach (ChestFields chestItem in chestItems) { var productId = chestItem.ProductId; var productCount = chestItem.Count; ChestFields productProperties = userChest.GetProductProperties(productId, productCount, lang.ToUpper()); result.Add(productId, productProperties); } // result.Add("chestItems", _getModel().ChestInactiveItems(userId)); // result.Add("chestItemCounts", chestItems); // // var store = new Store(); // var chestItemProperties = new ArrayList(); // // foreach (ChestFields chestItem in chestItems) // { // chestItemProperties.Add(store.GetPropertyById(chestItem.ProductId)); // } // result.Add("chestItemDescriptions", chestItemProperties); return(Json(result)); }
public IHttpActionResult PostActivateProduct(ActivateUserProduct data) { //Todo доабвить локаль для перевода string userId = User.Identity.GetUserId(); Store store = new Store(); StoreItem parameters = store.GetProductParametersByProductId(data.ProductId); int productType = parameters.product_typeId; Dictionary <string, dynamic> properties = System.Web.Helpers.Json.Decode(parameters.property); UserChest userChest = new UserChest(); ChestFields chestItem = userChest.GetChestData(userId, data.ProductId, false); if (MONEY_SG_TYPE == productType) { return(Json("MONEY_SG_TYPE")); } else if (PREMIUM_TYPE == productType) { Premium premium = new Premium(); premium.InitializePremium(userId, chestItem.Id, properties); } // else if (ACCOUNT_TYPE_SERVICE == productType) // { // return Json(productType); // } else if (BOOSTER_TYPE == productType) { Booster booster = new Booster(); booster.InitializeBooster(userId, chestItem, parameters, data.ProductId); } // else if (SKIN_TYPE == productType) // { // return Json(productType); // } var chestItems = userChest.GetCountProductId(userId, false); var result = new Dictionary <int, ChestFields>(); foreach (ChestFields chstItem in chestItems) { var productId = chstItem.ProductId; var productCount = chstItem.Count; ChestFields productProperties = userChest.GetProductProperties(productId, productCount, data.Lang.ToUpper()); result.Add(productId, productProperties); } return(Json(result)); }
protected static object Cleaner(string userId, int productId, SiteDataContext db) { var inactiveItems = db.booster .Where( p => p.userId == userId && p.finished == false && (p.storeProductId == productId || p.endTime < DateTime.UtcNow)) .Select(p => p); foreach (var item in inactiveItems) { UserChest.SetFinalize(item.user_chestId); item.finished = true; } return(new { Cleaner = "Cleaner true" }); }
protected object UpdateActivation(BoosterField data) { var db = new SiteDataContext(); try { db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); var userId = data.UserId; var userChestId = data.UserChestId; var storeProductId = data.StoreProductId; var basicDuration = data.BasicDuration; var currDate = DateTime.UtcNow; Cleaner(userId, storeProductId, db); var curEndTime = GetMaxEndTime(userId, storeProductId, currDate, db); var boosterProperty = GetItemProperty(storeProductId); db.booster.InsertOnSubmit(new booster { userId = userId, user_chestId = userChestId, storeProductId = storeProductId, basicDuration = basicDuration, property = boosterProperty, startTime = currDate, endTime = currDate.AddSeconds(basicDuration).Add(curEndTime - currDate) }); db.SubmitChanges(); var userChest = new UserChest(); userChest.UpdateActivateData(userChestId); db.Transaction.Commit(); return(new { userId, user_chestId = userChestId, storeProductId, basicDuration, property = boosterProperty, startTime = currDate, endTime = currDate.AddSeconds(basicDuration).Add(curEndTime - currDate) }); } catch (Exception) { db.Transaction.Rollback(); return(new { Rollback = "Rollback" }); } finally { db.Transaction.Dispose(); db.Connection.Close(); } }