Example #1
0
        //For Reseller
        public List <Models.GridPriceList> GetForReseller(int Id)
        {
            try
            {
                var db    = new Context.ConnectionStringsContext();
                var query = (from p in db.MicrosoftPriceList
                                                    //join rp in db.ResellerPrice
                                                    //on p.MicrosoftId equals rp.MicrosoftId
                                                    //into rps
                                                    //from rp in rps.DefaultIfEmpty()
                             where p.Status == true //&& rp.ResellerId == Id
                             group p by p.MicrosoftId into op
                             select new
                {
                    MicrosoftId = op.Key,
                    Name = op.Max(x => x.Name),
                    StartDate = op.Max(x => x.StartDate),
                    EndDate = op.Max(x => x.EndDate),
                    Price = op.Max(x => x.Price),
                    ResellerPrice = db.ResellerPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id && m.Status == true) ?
                                    db.ResellerPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id && m.Status == true).OrderByDescending(m => m.Id).FirstOrDefault().Price :
                                    (db.ResellerCustomersPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0 && m.ResellerPrice != null))
                                                 ? db.ResellerCustomersPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0).OrderByDescending(m => m.Id).FirstOrDefault().ResellerPrice : 0,
                    CustomerPrice = (db.CustomerPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id))
                                                    ? (db.CustomerPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id)).OrderByDescending(m => m.Id).FirstOrDefault().Price
                                                    : (db.ResellerCustomersPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id && m.CustomerPrice != null)) ?
                                    db.ResellerCustomersPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == Id).OrderByDescending(m => m.Id).FirstOrDefault().CustomerPrice
                                                    : op.Max(x => x.CustomerPrice),
                    AgreementType = op.Max(x => x.AgreementType),
                    CustomerType = op.Max(x => x.CustomerType),
                    LicenseType = op.Max(x => x.LicenseType),
                    PurchaseUnit = op.Max(x => x.PurchaseUnit),
                    PurchaseUnitNumber = op.Max(x => x.PurchaseUnitNumber),
                    Id = op.Max(x => x.Id),
                    DefaultMarginReseller = db.Resellers.Where(m => m.Id == Id).FirstOrDefault().Margin                //get the margin from reseller table
                }).ToList();



                List <Models.GridPriceList> mic = query.ToList().Select(r => new Models.GridPriceList
                {
                    EndDate     = r.EndDate,
                    Id          = r.Id,
                    MicrosoftId = r.MicrosoftId,
                    Name        = r.Name,
                    StartDate   = r.StartDate,
                    // Date = r.StartDate.Date + "<br/> "+r.EndDate.Date,
                    Price                   = r.Price,
                    AgreementType           = AgreementTypes.ParseEnumToString <AgreementType>(r.AgreementType),
                    CustomerType            = CustomerTypes.ParseEnumToString <CustomerType>(r.CustomerType),
                    LicenseType             = LicenseTypes.ParseEnumToString <LicenseType>(r.LicenseType),
                    ResellerPrice           = (double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100),
                    ResellerPricePercentage = ((double)System.Math.Round(((double)((((double)r.ResellerPrice != 0 ?
                                                                                     (double)r.ResellerPrice
                    : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100)) - r.Price) * 100) / r.Price), 2)).ToString(),
                    //((double)System.Math.Round(((double)((((double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.CustomerPrice - (r.CustomerPrice * r.DefaultMarginReseller) / 100)) - r.Price) * 100) / r.Price), 2)).ToString(),
                    CustomerPrice           = r.CustomerPrice,
                    CustomerPricePercentage = ((double)System.Math.Round((((r.CustomerPrice - ((double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100))) * 100) / ((double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100))), 2)).ToString(),
                    PurchaseUnit            = r.PurchaseUnitNumber + " " + PurchaseUnits.ParseEnumToString <PurchaseUnit>(r.PurchaseUnit),
                    //PurchaseUnitNumber = r.PurchaseUnitNumber,
                    DefaultMarginReseller = (double)r.ResellerPrice != 0 ?

                                            ((double)((

                                                          ((double)System.Math.Round((((r.CustomerPrice - r.Price) * 100) / r.Price), 2))
                                                          -
                                                          ((double)System.Math.Round(((double)((((double)r.ResellerPrice != 0 ?
                                                                                                 (double)r.ResellerPrice
                    : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100)) - r.Price) * 100) / r.Price), 2)))
                                                      * 100
                                                      )
                                             / ((double)(((double)System.Math.Round((((r.CustomerPrice - r.Price) * 100) / r.Price), 2))))
                                            ).ToString()
                    : r.DefaultMarginReseller.ToString()
                }).OrderBy(m => m.Name).ToList();

                return(mic);
            }
            catch
            {
                return(new List <Models.GridPriceList>());
            }
        }
Example #2
0
        //For Admin (Overall price list => ResellerPrice > MicrosoftPriceList)
        public List <Models.GridPriceList> GetGridPriceListForAdmin()
        {
            //IEnumerable<MicrosoftOffer> microsoftOffers = await ApplicationDomain.Instance.OffersRepository.RetrieveMicrosoftOffersAsync().ConfigureAwait(false);
            try
            {
                var db    = new Context.ConnectionStringsContext();
                var query = (from p in db.MicrosoftPriceList
                             // join
                             where p.Status == true
                             group p by p.MicrosoftId into op
                             select new
                {
                    MicrosoftId = op.Key,
                    Name = op.Max(x => x.Name),
                    StartDate = op.Max(x => x.StartDate),
                    EndDate = op.Max(x => x.EndDate),
                    Price = op.Max(x => x.Price),
                    ResellerPrice = (db.ResellerCustomersPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0 && m.ResellerPrice != null))
                                                 ? db.ResellerCustomersPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0).OrderByDescending(m => m.Id).FirstOrDefault().ResellerPrice
                                                 : 0,
                    //op.Max(x => x.CustomerPrice) - (op.Max(x => x.CustomerPrice) * (db.DefaultMargin.Where(m => m.ResellerId == 0 && m.Role == (int)Roles.Resellers).FirstOrDefault().DefaultPercentage)) / 100,

                    //ResellerPrice = (db.ResellerCustomersPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0 && m.ResellerPrice != null)) ?
                    //               db.ResellerCustomersPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0).FirstOrDefault().ResellerPrice
                    //               : op.Max(x => x.ResellerPrice),
                    CustomerPrice = (db.ResellerCustomersPrice.Any(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0 && m.CustomerPrice != null)) ?
                                    db.ResellerCustomersPrice.Where(m => m.PriceId == op.Max(x => x.Id) && m.ResellerId == 0).OrderByDescending(m => m.Id).FirstOrDefault().CustomerPrice
                                                : op.Max(x => x.CustomerPrice),
                    AgreementType = op.Max(x => x.AgreementType),
                    CustomerType = op.Max(x => x.CustomerType),
                    LicenseType = op.Max(x => x.LicenseType),
                    PurchaseUnit = op.Max(x => x.PurchaseUnit),
                    PurchaseUnitNumber = op.Max(x => x.PurchaseUnitNumber),
                    Id = op.Max(x => x.Id),
                    DefaultMarginReseller = db.DefaultMargin.Where(m => m.ResellerId == 0 && m.Role == (int)Roles.Resellers).FirstOrDefault().DefaultPercentage
                }).ToList();



                List <Models.GridPriceList> mic = query.ToList().Select(r => new Models.GridPriceList
                {
                    EndDate     = r.EndDate,
                    Id          = r.Id,
                    MicrosoftId = r.MicrosoftId,
                    Name        = r.Name,
                    StartDate   = r.StartDate,
                    // Date = r.StartDate.Date + "<br/> "+r.EndDate.Date,
                    Price                   = r.Price,
                    AgreementType           = AgreementTypes.ParseEnumToString <AgreementType>(r.AgreementType),
                    CustomerType            = CustomerTypes.ParseEnumToString <CustomerType>(r.CustomerType),
                    LicenseType             = LicenseTypes.ParseEnumToString <LicenseType>(r.LicenseType),
                    ResellerPrice           = (double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100),
                    ResellerPricePercentage = ((double)System.Math.Round(((double)(((
                                                                                        (double)r.ResellerPrice != 0
                    ? (double)r.ResellerPrice
                    : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100)
                                                                                        ) - r.Price) * 100) / r.Price), 2)).ToString(),
                    //ResellerPrice = (double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.CustomerPrice - (r.CustomerPrice * r.DefaultMarginReseller) / 100),
                    //ResellerPricePercentage = ((double)System.Math.Round(((double)((((double)r.ResellerPrice != 0 ? (double)r.ResellerPrice : (r.CustomerPrice - (r.CustomerPrice * r.DefaultMarginReseller) / 100)) - r.Price) * 100) / r.Price), 2)).ToString(),
                    CustomerPrice           = r.CustomerPrice,
                    CustomerPricePercentage = ((double)System.Math.Round((((r.CustomerPrice - r.Price) * 100) / r.Price), 2)).ToString(),
                    PurchaseUnit            = r.PurchaseUnitNumber + " " + PurchaseUnits.ParseEnumToString <PurchaseUnit>(r.PurchaseUnit),
                    //PurchaseUnitNumber = r.PurchaseUnitNumber,
                    DefaultMarginReseller = (double)r.ResellerPrice != 0 ?

                                            ((double)((

                                                          ((double)System.Math.Round((((r.CustomerPrice - r.Price) * 100) / r.Price), 2))
                                                          -
                                                          ((double)System.Math.Round(((double)((((double)r.ResellerPrice != 0 ?
                                                                                                 (double)r.ResellerPrice
                    : (r.Price + ((r.CustomerPrice - r.Price) * r.DefaultMarginReseller) / 100)) - r.Price) * 100) / r.Price), 2)))
                                                      * 100
                                                      )
                                             / ((double)(((double)System.Math.Round((((r.CustomerPrice - r.Price) * 100) / r.Price), 2))))
                                            ).ToString()
                    : r.DefaultMarginReseller.ToString()
                }).OrderBy(m => m.Name).ToList();

                return(mic);
            }
            catch (Exception ex)
            {
                return(new List <Models.GridPriceList>());
            }
        }