SubscriptionPriceModel.cs 4.35 KB
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<SubscriptionPriceModel> GetSubscriptionPrices(AIADatabaseV5Entities dbContext, int editionId, int pageNo, int pageLength, out int recordCount)
        {
            List<SubscriptionPriceModel> SubscriptionPriceList = new List<SubscriptionPriceModel>();
            SubscriptionPriceModel SubscriptionPriceObj = new SubscriptionPriceModel();
            var spRecordCount = new System.Data.Objects.ObjectParameter("recordCount", 0);
            recordCount = 0;
            try
            {
                var result = dbContext.usp_GetSubscriptionPlans((byte?)editionId, pageNo, pageLength, spRecordCount).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);
                    }
                }
                recordCount = (int)spRecordCount.Value;
            }
            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<SubscriptionPriceModel> 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 DeleteSubscriptionPrice(AIADatabaseV5Entities dbContext, int subscriptionPriceId)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.usp_DeleteSubscriptionPlan((byte?)subscriptionPriceId, spStatus);
                return (bool)spStatus.Value;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static bool CheckSubscriptionPlanForLicense(AIADatabaseV5Entities dbContext, int subscriptionPriceId)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.usp_CheckSubscriptionForLicense((byte?)subscriptionPriceId, spStatus);
                return (bool)spStatus.Value;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }
}