using System; using System.Collections.Generic; using System.Linq; using System.Web; using AIAHTML5.ADMIN.API.Entity; namespace AIAHTML5.ADMIN.API.Models { public class DiscountCodeModel { public int Id { get; set; } public string DiscountCode { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public bool IsActive { get; set; } public decimal Percentage { get; set; } public static List GetDiscountCodes(AIADatabaseV5Entities dbContext, string discountCode, DateTime startDate, DateTime endDate, string sortColumn, string sortOrder, int pageNo, int pageLength, out int recordCount) { List DiscountCodeList = new List(); var spRecordCount = new System.Data.Objects.ObjectParameter("recordCount", 0); recordCount = 0; try { DiscountCodeList = dbContext.usp_GetDiscountCodes(discountCode, startDate.ToString("MM/dd/yyyy"), endDate.ToString("MM/dd/yyyy"), sortColumn, sortOrder, pageNo, pageLength, spRecordCount).ToList(); recordCount = (int)spRecordCount.Value; } catch (Exception ex) { } return DiscountCodeList; } public static bool InsertDiscountCode(AIADatabaseV5Entities dbContext, DiscountCodeModel discountCodeModel) { try { var result = dbContext.usp_InsertNewDiscount(discountCodeModel.Percentage, discountCodeModel.StartDate.ToString("MM/dd/yyyy"), discountCodeModel.EndDate.ToString("MM/dd/yyyy"), discountCodeModel.DiscountCode); if (result.Count() > 0) { return true; } else { return false; } } catch (Exception ex) { return false; } } public static bool UpdateDiscountCode(AIADatabaseV5Entities dbContext, DiscountCodeModel discountCodeModel) { try { var result = dbContext.usp_UpdateDiscount(discountCodeModel.Id, discountCodeModel.Percentage, discountCodeModel.StartDate.ToString("MM/dd/yyyy"), discountCodeModel.EndDate.ToString("MM/dd/yyyy"), (byte?)(discountCodeModel.IsActive == true ? 1 : 0), discountCodeModel.DiscountCode); if (result.Count() > 0) { return true; } else { return false; } } catch (Exception ex) { return false; } } } }