SubscriptionPriceModel.cs 4.06 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 duration)
        {
            List<SubscriptionPriceModel> SubscriptionPriceList = new List<SubscriptionPriceModel>();
            SubscriptionPriceModel SubscriptionPriceObj = new SubscriptionPriceModel();
            try
            {
                var result = dbContext.Usp_GetSubscriptionPlans((byte?)editionId, (byte?)duration).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.Id;
                        SubscriptionPriceObj.IsActive =  true ;
                        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);
                if (spStatus.Value.ToString() == "1")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public static bool UpdateSubscriptionPrice(AIADatabaseV5Entities dbContext, SubscriptionPriceModel subscriptionPriceModel)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.Usp_UpdateSubscriptionPlan((byte?)subscriptionPriceModel.Id, subscriptionPriceModel.Title, subscriptionPriceModel.Price,
                    (byte?)subscriptionPriceModel.Duration, (byte?)subscriptionPriceModel.EditionId, subscriptionPriceModel.IsActive, spStatus);
                if (spStatus.Value.ToString() == "1")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            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);
                if (spStatus.Value.ToString() == "1")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}