using System; using System.Collections.Generic; using System.Linq; using System.Web; using AIAHTML5.ADMIN.API.Entity; namespace AIAHTML5.ADMIN.API.Models { public class SubscriptionPriceModel { public int Id { get; set; } public string Title { get; set; } public decimal Price { get; set; } public int Duration { get; set; } public int EditionId { get; set; } public bool IsActive { get; set; } public static List GetSubscriptionPrices(AIADatabaseV5Entities dbContext, int editionId) { List SubscriptionPriceList = new List(); SubscriptionPriceModel SubscriptionPriceObj = new SubscriptionPriceModel(); try { var result = dbContext.usp_GetSubscriptionPlans((byte?)editionId).ToList(); if (result.Count > 0) { foreach (var item in result) { SubscriptionPriceObj = new SubscriptionPriceModel(); SubscriptionPriceObj.Id = item.Id; SubscriptionPriceObj.Title = item.title; SubscriptionPriceObj.Price = item.price.Value; SubscriptionPriceObj.Duration = item.Duration; SubscriptionPriceObj.EditionId = item.EditionId; SubscriptionPriceObj.IsActive = item.IsActive; SubscriptionPriceList.Add(SubscriptionPriceObj); } } } catch (Exception ex) { } return SubscriptionPriceList; } public static bool InsertSubscriptionPrice(AIADatabaseV5Entities dbContext, SubscriptionPriceModel subscriptionPriceModel) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { dbContext.usp_InsertSubscriptionPlan((byte?)subscriptionPriceModel.Id, subscriptionPriceModel.Title, (decimal?)subscriptionPriceModel.Price, (byte?)subscriptionPriceModel.Duration, (byte?)subscriptionPriceModel.EditionId, subscriptionPriceModel.IsActive, spStatus); return (bool)spStatus.Value; } catch (Exception ex) { return false; } } public static bool UpdateSubscriptionPrices(AIADatabaseV5Entities dbContext, List subscriptionPriceList) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { foreach (var item in subscriptionPriceList) { dbContext.usp_UpdateSubscriptionPlan((byte?)item.Id, item.Title, item.Price, (byte?)item.Duration, (byte?)item.EditionId, item.IsActive, spStatus); if (!(bool)spStatus.Value) break; } return (bool)spStatus.Value; } catch (Exception ex) { return false; } } public static bool DeleteSubscriptionPrices(AIADatabaseV5Entities dbContext, List subscriptionPriceIds) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { foreach (var item in subscriptionPriceIds) { dbContext.usp_DeleteSubscriptionPlan((byte?)item, spStatus); if (!(bool)spStatus.Value) break; } return (bool)spStatus.Value; } catch (Exception ex) { return false; } } } }