Example #1
0
        //Get Price List by Id
        public Models.MicrosoftPriceList GetPriceById(string id)
        {
            try
            {
                var db = new Context.ConnectionStringsContext();

                var query = (from p in db.MicrosoftPriceList
                             where p.Status == true && p.MicrosoftId == id
                             group p by p.MicrosoftId into op

                             select new
                {
                    MicrosoftId = op.Key,

                    Price = op.Max(x => x.Price),
                    //ResellerPrice = op.Max(x => x.ResellerPrice),
                    //ResellerPrice = op.Max(x => x.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 : op.Max(x => x.ResellerPrice),
                    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 : 0,
                    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).FirstOrDefault().CustomerPrice
                                                : op.Max(x => x.CustomerPrice), //op.Max(x => x.CustomerPrice),
                    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
                }).SingleOrDefault();

                Models.MicrosoftPriceList mic = new Models.MicrosoftPriceList
                {
                    Id                 = query.Id,
                    MicrosoftId        = query.MicrosoftId,
                    Price              = query.Price,
                    ResellerPrice      = (double)query.ResellerPrice != 0 ? (double)query.ResellerPrice : (query.CustomerPrice - (query.CustomerPrice * query.DefaultMarginReseller) / 100),
                    CustomerPrice      = query.CustomerPrice,
                    PurchaseUnit       = query.PurchaseUnit,
                    PurchaseUnitNumber = query.PurchaseUnitNumber,
                };
                return(mic);
            }
            catch
            {
                return(new Models.MicrosoftPriceList());
            }
        }
Example #2
0
 private Models.MicrosoftPriceList SaveList(ExcelPriceList lm, bool status)
 {
     Models.MicrosoftPriceList microsoftPriceList = new Models.MicrosoftPriceList
     {
         CustomerPrice      = lm.CustomerPrice,
         EndDate            = lm.EndDate,
         MicrosoftId        = lm.MicrosoftId,
         Name               = lm.Name,
         Price              = lm.Price,
         PurchaseUnit       = lm.PurchaseUnit,
         PurchaseUnitNumber = lm.PurchaseUnitNumber,
         ResellerPrice      = lm.ResellerPrice,
         StartDate          = lm.StartDate,
         Status             = status,
         AgreementType      = lm.AgreementType,
         CustomerType       = lm.CustomerType,
         LicenseType        = lm.LicenseType
     };
     return(microsoftPriceList);
 }
Example #3
0
        public void SavePriceList(List <Models.ExcelPriceList> _m)
        {
            try
            {
                var db = new Context.ConnectionStringsContext();
                foreach (var lm in _m)
                {
                    if (((Models.OfferActionType)lm.ActionType == Models.OfferActionType.ADD || (Models.OfferActionType)lm.ActionType == Models.OfferActionType.CHG) && !db.MicrosoftPriceList.Any(m => m.MicrosoftId == lm.MicrosoftId && m.Price == lm.Price && m.CustomerPrice == lm.CustomerPrice && m.AgreementType == lm.AgreementType && m.CustomerType == lm.CustomerType && m.LicenseType == lm.LicenseType))
                    {
                        // A new offer added
                        //if (!db.MicrosoftPriceList.Any(m => m.MicrosoftId == lm.MicrosoftId))
                        //{
                        Models.MicrosoftPriceList microsoftPriceList = SaveList(lm, true);
                        db.MicrosoftPriceList.Add(microsoftPriceList);
                        //}
                    }
                    else if ((Models.OfferActionType)lm.ActionType == Models.OfferActionType.DEL)    // soft Delete the rec
                    {
                        var p = db.MicrosoftPriceList.Where(m => m.MicrosoftId == lm.MicrosoftId).SingleOrDefault();
                        if (p == null) //if not exit then add and aplly soft deletion action
                        {
                            Models.MicrosoftPriceList microsoftPriceList = SaveList(lm, false);
                            db.MicrosoftPriceList.Add(microsoftPriceList);
                        }
                        else if (p.Status == true) // if exist and it's status is true then soft deletion action occur
                        {
                            p.Status = false;
                        }
                    }
                    else if ((Models.OfferActionType)lm.ActionType == Models.OfferActionType.UNC)  // do not change record
                    {
                        var p = db.MicrosoftPriceList.Where(m => m.MicrosoftId == lm.MicrosoftId).SingleOrDefault();
                        if (p == null) // if not exit then add a new data otherwise do not apllying any changes if it's exist
                        {
                            Models.MicrosoftPriceList microsoftPriceList = SaveList(lm, true);
                            db.MicrosoftPriceList.Add(microsoftPriceList);
                        }
                    }

                    //if (!db.MicrosoftPriceList.Any(m => m.MicrosoftId == lm.MicrosoftId && m.EndDate == lm.EndDate && m.StartDate == lm.StartDate && m.Price == lm.Price))
                    //{
                    //    Models.MicrosoftPriceList microsoftPriceList = new Models.MicrosoftPriceList
                    //    {
                    //        CustomerPrice = lm.CustomerPrice,
                    //        EndDate = lm.EndDate,
                    //        MicrosoftId = lm.MicrosoftId,
                    //        Price = lm.Price,
                    //        PurchaseUnit = lm.PurchaseUnit,
                    //        PurchaseUnitNumber = lm.PurchaseUnitNumber,
                    //        ResellerPrice = lm.ResellerPrice,
                    //        StartDate = lm.StartDate,
                    //    };
                    //    db.MicrosoftPriceList.Add(microsoftPriceList);
                    //}
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
            }
        }