Esempio n. 1
0
        public IHttpActionResult ValidateAllInputs()
        {
            IHttpActionResult lResult = null;
            var lLogMsg = string.Empty;
            var lInputs = new List <String>();
            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    lInputs = db.ValidateAllInputs(Convert.ToInt16(lCookieData.Year), lCookieData.BookID, lCookieData.VersionID)
                              .ToList();
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in ValidateAllInputs.  Publisher: {0}, Book: {1}, BookID: {2}.", lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                return(lResult = BadRequest(lReturnMessage));
            }

            if (lInputs.Any())
            {
                lResult = Ok(lInputs);
            }
            else
            {
                lResult = Ok();
            }
            return(lResult);
        }
Esempio n. 2
0
        public List <TabletModel> GetTabletRates()
        {
            var lResult           = new List <TabletModel>();
            var lLogMsg           = string.Empty;
            var lTableRatesOutput = new List <TabletModel>();
            var pContext          = System.Web.HttpContext.Current;

            // Get BookID, VersionID & Year from Cookie
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    var lTabletRates = db.GetTabletRates(lCookieData.Year, lCookieData.BookID, lCookieData.VersionID)
                                       .ToList();

                    if (lTabletRates.Any())
                    {
                        foreach (var tabletRate in lTabletRates)
                        {
                            //recordCount++;

                            var newTableRateRecord = new TabletModel
                            {
                                TabletFunctionalityID     = tabletRate.TabletFunctionalityID,
                                TabletParentFunctionality = tabletRate.TabletParentFunctionality,
                                TabletFunctionality       = tabletRate.TabletFunctionality
                            };
                            if (tabletRate.EarnedRate != null)
                            {
                                newTableRateRecord.EarnedRate = Convert.ToInt32(tabletRate.EarnedRate);
                            }
                            if (tabletRate.OpenRate != null)
                            {
                                newTableRateRecord.OpenRate = Convert.ToInt32(tabletRate.OpenRate);
                            }

                            lTableRatesOutput.Add(newTableRateRecord);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in Repository GetTabletRates method.");
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                throw new Exception(lReturnMessage);
            }
            if (lTableRatesOutput.Any())
            {
                lResult = lTableRatesOutput;
            }

            return(lResult);
        }
        public IHttpActionResult savePublisherAgreements(List <PublisherAgreement> answers)
        {
            IHttpActionResult lResult = null;
            var lLogMsg = string.Empty;
            var lRateID = int.MinValue;

            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    foreach (var answer in answers)
                    {
                        var lRates = db.Rates.Where(r => (r.Year == lCookieData.Year &&
                                                          r.BookID == lCookieData.BookID &&
                                                          r.VersionID == lCookieData.VersionID &&
                                                          r.RateTypeID == answer.RateTypeID &&
                                                          r.AdTypeID == answer.AdTypeID &&
                                                          r.EditionTypeID == answer.EditionTypeID)).ToList();

                        if (lRates.Any())
                        {
                            // Update
                            foreach (var lRate in lRates)
                            {
                                if (answer.Answer != string.Empty)
                                {
                                    lRate.PublisherAgreement = answer.Answer;
                                }
                            }
                        }
                    }
                    lRateID = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in savePublisherAgreements.  Publisher: {0}, Book: {1}, BookID: {2}.", lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                lResult = BadRequest(lReturnMessage);
            }

            if (lRateID > int.MinValue)
            {
                lResult = Ok(lRateID);
            }
            else
            {
                lResult = Ok();
            }
            return(lResult);
        }
        // DELETE api/<controller>/5
        public void Delete(int id)
        {
            using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
            {
                //var lCalRecord = db.EditorialCalendars.Find(id);
                var lCalRecord = new EditorialCalendar();
                lCalRecord.EditorialCalendarID = id;

                db.EditorialCalendars.Attach(lCalRecord);
                db.EditorialCalendars.Remove(lCalRecord);
                db.SaveChanges();
            }
        }
Esempio n. 5
0
        public List <EditorialCalendarModel> GetCalendar()
        {
            var lResult = new List <EditorialCalendarModel>();
            var lLogMsg = string.Empty;
            var lEditorialCalendarOutput = new List <EditorialCalendarModel>();
            var lstEditorialRecords      = new List <loreal_print.Models.EditorialCalendar>();

            var pContext = HttpContext.Current;

            // Get BookID, VersionID & Year from Cookie
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    lstEditorialRecords = db.EditorialCalendars
                                          .Where(e => e.BookID == lCookieData.BookID && e.Year == lCookieData.Year && e.VersionID == lCookieData.VersionID)
                                          .ToList();

                    if (lstEditorialRecords.Any())
                    {
                        foreach (var calItem in lstEditorialRecords)
                        {
                            //recordCount++;

                            var newEditorialCalendarOutput = new EditorialCalendarModel
                            {
                                EditorialCalendarID = calItem.EditorialCalendarID,
                                BookID                          = Convert.ToInt32(lCookieData.BookID),
                                Year                            = lCookieData.Year,
                                VersionID                       = lCookieData.VersionID,
                                IssueDate                       = calItem.IssueDate,
                                EditorialTheme                  = calItem.EditorialTheme,
                                OnSaleDate                      = calItem.OnSaleDate.ToString("MM/dd/yyyy"),
                                MailToSubscribersDate           = calItem.MailToSubscribersDate.ToString("MM/dd/yyyy"),
                                SpaceClosingDateROB             = calItem.SpaceClosingDate_ROB.ToString("MM/dd/yyyy"),
                                SpaceClosingDateCovers          = calItem.SpaceClosingDate_Covers.ToString("MM/dd/yyyy"),
                                SpaceClosingDateScentStrips     = calItem.SpaceClosingDate_ScentStrips.ToString("MM/dd/yyyy"),
                                MaterialsClosingDateROB         = calItem.MaterialsClosingDate_ROB.ToString("MM/dd/yyyy"),
                                MaterialsClosingDateCovers      = calItem.MaterialsClosingDate_Covers.ToString("MM/dd/yyyy"),
                                MaterialsClosingDateScentStrips = calItem.MaterialsClosingDate_ScentStrips.ToString("MM/dd/yyyy")
                            };
                            lEditorialCalendarOutput.Add(newEditorialCalendarOutput);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in Repository EditorialCalendar GetCalendar method.  Publisher: {0}, Book: {1}, BookID: {2}.", lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                throw new Exception(lReturnMessage);
            }
            if (lEditorialCalendarOutput.Any())
            {
                lResult = lEditorialCalendarOutput;
            }

            return(lResult);
        }
        public IHttpActionResult saveEditorialCalendar(EditorialCalendarModel calendarRecord)
        {
            /* There is no way to guarantee uniqueness.  Therefore, whenever changes/additions are made:
             * 1. All records are sent up
             * 2. All existing records are DELETED
             * 3. All records included in the calendarRecords collection are INSERTED */

            IHttpActionResult lResult = null;
            var lLogMsg = string.Empty;
            var lEditorialCalendarID = int.MinValue;

            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            // Verify Incoming Date Values passed as Strings
            var isValidDate = calendarRecord.ValidateDateFields(calendarRecord);

            if (ModelState.IsValid && isValidDate)
            {
                if (calendarRecord != null)
                {
                    try
                    {
                        using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                        {
                            if (calendarRecord.EditorialCalendarID > 0)
                            {
                                // Update Existing record
                                var lUpdateCalRecord = db.EditorialCalendars.Find(calendarRecord.EditorialCalendarID);

                                lUpdateCalRecord.Year                             = lCookieData.Year;
                                lUpdateCalRecord.BookID                           = Convert.ToInt32(lCookieData.BookID);
                                lUpdateCalRecord.VersionID                        = lCookieData.VersionID;
                                lUpdateCalRecord.IssueDate                        = calendarRecord.IssueDate;
                                lUpdateCalRecord.EditorialTheme                   = calendarRecord.EditorialTheme;
                                lUpdateCalRecord.OnSaleDate                       = Convert.ToDateTime(calendarRecord.OnSaleDate);
                                lUpdateCalRecord.MailToSubscribersDate            = Convert.ToDateTime(calendarRecord.MailToSubscribersDate);
                                lUpdateCalRecord.SpaceClosingDate_ROB             = Convert.ToDateTime(calendarRecord.SpaceClosingDateROB);
                                lUpdateCalRecord.SpaceClosingDate_Covers          = Convert.ToDateTime(calendarRecord.SpaceClosingDateCovers);
                                lUpdateCalRecord.SpaceClosingDate_ScentStrips     = Convert.ToDateTime(calendarRecord.SpaceClosingDateScentStrips);
                                lUpdateCalRecord.MaterialsClosingDate_ROB         = Convert.ToDateTime(calendarRecord.MaterialsClosingDateROB);
                                lUpdateCalRecord.MaterialsClosingDate_Covers      = Convert.ToDateTime(calendarRecord.MaterialsClosingDateCovers);
                                lUpdateCalRecord.MaterialsClosingDate_ScentStrips = Convert.ToDateTime(calendarRecord.MaterialsClosingDateScentStrips);
                            }
                            else
                            {
                                // Create
                                var lNewCalRecord = new EditorialCalendar
                                {
                                    Year                             = lCookieData.Year,
                                    BookID                           = Convert.ToInt32(lCookieData.BookID),
                                    VersionID                        = lCookieData.VersionID,
                                    IssueDate                        = calendarRecord.IssueDate,
                                    EditorialTheme                   = calendarRecord.EditorialTheme,
                                    OnSaleDate                       = Convert.ToDateTime(calendarRecord.OnSaleDate),
                                    MailToSubscribersDate            = Convert.ToDateTime(calendarRecord.MailToSubscribersDate),
                                    SpaceClosingDate_ROB             = Convert.ToDateTime(calendarRecord.SpaceClosingDateROB),
                                    SpaceClosingDate_Covers          = Convert.ToDateTime(calendarRecord.SpaceClosingDateCovers),
                                    SpaceClosingDate_ScentStrips     = Convert.ToDateTime(calendarRecord.SpaceClosingDateScentStrips),
                                    MaterialsClosingDate_ROB         = Convert.ToDateTime(calendarRecord.MaterialsClosingDateROB),
                                    MaterialsClosingDate_Covers      = Convert.ToDateTime(calendarRecord.MaterialsClosingDateCovers),
                                    MaterialsClosingDate_ScentStrips = Convert.ToDateTime(calendarRecord.MaterialsClosingDateScentStrips),

                                    Load_Date = DateTime.Now
                                };
                                db.EditorialCalendars.Add(lNewCalRecord);
                            }
                            //var lCalRecords = db.EditorialCalendars.Where(c => (c.Year == lCookieData.Year
                            //                    && c.BookID == lCookieData.BookID
                            //                    && c.VersionID == lCookieData.VersionID
                            //                   )).ToList();

                            //if (lCalRecords.Any())
                            //{
                            //    // Delete all existing records.
                            //    //obj.tblA.Where(x => x.fid == i).ToList().ForEach(obj.tblA.DeleteObject);
                            //    //obj.SaveChanges();
                            //    foreach (var calRecord in lCalRecords)
                            //    {
                            //        db.EditorialCalendars.Remove(calRecord);
                            //    }
                            //}
                            //lCircID = db.SaveChanges();

                            // Create All records sent
                            //foreach (var calItem in calendarRecords)
                            //{

                            //}
                            lEditorialCalendarID = db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        var lReturnMessage = String.Format("Error in saveEditorialCalendar.  Publisher: {0}, Book: {1}, BookID: {2}.",
                                                           lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                        lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                        logger.Error(lLogMsg);
                        lResult = BadRequest(lReturnMessage);
                    }
                }
            }
            else
            {
                string errorMessages = string.Empty;

                if (ModelState.Values.Any())
                {
                    errorMessages = string.Join("; ", ModelState.Values
                                                .SelectMany(e => e.Errors)
                                                .Select(e => e.ErrorMessage));
                }
                else
                {
                    errorMessages = calendarRecord.EditorialErrorMsg;
                }
                return(BadRequest(errorMessages));
            }

            if (lEditorialCalendarID > int.MinValue)
            {
                lResult = Ok(lEditorialCalendarID);
            }
            else
            {
                lResult = Ok();
            }
            return(lResult);
        }
Esempio n. 7
0
        public IHttpActionResult saveTabletRates(List <TabletModel> rates)
        {
            IHttpActionResult lResult = null;
            var lLogMsg                = string.Empty;
            var lTabletRateID          = int.MinValue;
            var lTabletFunctionalityID = int.MinValue;

            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            if (ModelState.IsValid)
            {
                try
                {
                    using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                    {
                        foreach (var rate in rates)
                        {
                            lTabletFunctionalityID = rate.TabletFunctionalityID; // For reference in case of error.
                            var lTabletRateRecord = db.TabletRates.Where(t => (t.Year == lCookieData.Year &&
                                                                               t.BookID == lCookieData.BookID &&
                                                                               t.VersionID == lCookieData.VersionID &&
                                                                               t.TabletFunctionalityID == lTabletFunctionalityID
                                                                               )).FirstOrDefault();

                            if (lTabletRateRecord != null)
                            {
                                // Update
                                if (rate.EarnedRate >= 0)
                                {
                                    lTabletRateRecord.EarnedRate = rate.EarnedRate;
                                }
                                if (rate.OpenRate >= 0)
                                {
                                    lTabletRateRecord.OpenRate = rate.OpenRate;
                                }
                                lTabletRateRecord.VersionID = lCookieData.VersionID;
                            }
                            else
                            {
                                // Create
                                var lNewTabletRateRecord = new TabletRate
                                {
                                    Year                  = lCookieData.Year,
                                    BookID                = Convert.ToInt32(lCookieData.BookID),
                                    VersionID             = lCookieData.VersionID,
                                    TabletFunctionalityID = lTabletFunctionalityID,
                                    Load_Date             = DateTime.Now
                                };
                                if (rate.EarnedRate >= 0)
                                {
                                    lNewTabletRateRecord.EarnedRate = rate.EarnedRate;
                                }
                                if (rate.OpenRate >= 0)
                                {
                                    lNewTabletRateRecord.OpenRate = rate.OpenRate;
                                }
                                lNewTabletRateRecord.VersionID = lCookieData.VersionID;

                                db.TabletRates.Add(lNewTabletRateRecord);
                            }
                        }
                        lTabletRateID = db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    var lReturnMessage = String.Format("Error in saveTabletRates.  TabletFunctionalityID: {0}, Publisher: {1}, Book: {2}, BookID: {3}.",
                                                       lTabletFunctionalityID, lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                    lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                    logger.Error(lLogMsg);
                    lResult = BadRequest(lReturnMessage);
                }
            }
            else
            {
                string errorMessages = string.Join("; ", ModelState.Values
                                                   .SelectMany(e => e.Errors)
                                                   .Select(e => e.ErrorMessage));

                return(lResult = BadRequest(errorMessages));
            }

            // If we got to this point the operation was successful
            if (lTabletRateID > int.MinValue)
            {
                lResult = Ok(lTabletRateID);
            }
            else
            {
                lResult = Ok();
            }
            return(lResult);
        }
        public IHttpActionResult saveCirculationRecords(List<CirculationContent> CircContent)
        {
            IHttpActionResult lResult = null;
            var lLogMsg = string.Empty;
            var lCircID = int.MinValue;
            var lCirculationSubTypeID = int.MinValue;

            // Get BookID, VersionID & Year from Cookie
            var pContext = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            if (ModelState.IsValid)
            {
                try
                {
                    using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                    {
                        foreach (var circ in CircContent)
                        {
                            lCirculationSubTypeID = circ.CirculationSubTypeID; // For reference in case of error.
                            var lCircRecord = db.Circulations.Where(c => (c.Year == lCookieData.Year
                                && c.BookID == lCookieData.BookID
                                && c.VersionID == lCookieData.VersionID
                                && c.CirculationSubTypeID == lCirculationSubTypeID
                               )).FirstOrDefault();

                            if (lCircRecord != null)
                            {
                                // Update
                                lCircRecord.DigitalNonReplicaCirculation = circ.DigitalNonReplicaCirculation;
                                lCircRecord.DigitalReplicaCirculation = circ.DigitalReplicaCirculation;
                                lCircRecord.PrintCirculation = circ.PrintCirculation;
                                lCircRecord.VersionID = lCookieData.VersionID;
                            }
                            else
                            {
                                // Create
                                var lNewCircRecord = new Models.Circulation
                                {
                                    Year = lCookieData.Year,
                                    BookID = Convert.ToInt32(lCookieData.BookID),
                                    VersionID = lCookieData.VersionID,
                                    CirculationSubTypeID = lCirculationSubTypeID,
                                    Load_Date = DateTime.Now
                                };
                                if (circ.PrintCirculation != null)
                                    lNewCircRecord.PrintCirculation = circ.PrintCirculation;
                                if (circ.DigitalNonReplicaCirculation != null)
                                    lNewCircRecord.DigitalNonReplicaCirculation = circ.DigitalNonReplicaCirculation;
                                if (circ.DigitalReplicaCirculation != null)
                                    lNewCircRecord.DigitalReplicaCirculation = circ.DigitalReplicaCirculation;

                                db.Circulations.Add(lNewCircRecord);
                            }
                        }
                        lCircID = db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    var lReturnMessage = String.Format("Error in saveCirculationRecords.  CirculationSubTypeID: {0}, Publisher: {1}, Book: {2}, BookID: {3}.",
                        lCirculationSubTypeID, lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                    lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                    logger.Error(lLogMsg);
                    lResult = BadRequest(lReturnMessage);
                }
            }
            else
            {
                string errorMessages = string.Join("; ", ModelState.Values
                                                        .SelectMany(e => e.Errors)
                                                        .Select(e => e.ErrorMessage));

                return lResult = BadRequest(errorMessages);
            }

            if (lCircID > int.MinValue)
            {
                lResult = Ok(lCircID);
            }
            else
            {
                lResult = Ok();
            }
            return lResult;
        }
Esempio n. 9
0
        public RatesReportModel GetRatesReport()
        {
            var lResult                = new RatesReportModel();
            var lLogMsg                = string.Empty;
            var lRatesReportOutput     = new List <RatesReportModel>();
            var newRatesReportOutput   = new RatesReportModel();
            var newRatesReportRateType = new RatesReportRateType();
            var newRatesReportAdType   = new RatesReportAdType();
            var lRatesReportAdTypeList = new List <RatesReportAdType>();
            var newRatesReportTier     = new RatesReportTier();
            var lRatesReportTierList   = new List <RatesReportTier>();
            var pContext               = System.Web.HttpContext.Current;
            var isRateOpen             = false;
            var isAdTypeOpen           = false;
            var isTierOpen             = false;
            var lRateTypeID            = 0;
            var lAdTypeID              = 0;
            var lTierID                = -1;
            var recordCount            = 0;

            // Get BookID, VersionID & Year from Cookie
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    var lRatesReportRecords = db.GetRatesEndReport(lCookieData.Year, lCookieData.BookID, lCookieData.VersionID)
                                              .ToList();

                    var recordTotal = lRatesReportRecords.Count;

                    newRatesReportOutput.BookID    = Convert.ToInt32(lCookieData.BookID);
                    newRatesReportOutput.VersionID = lCookieData.VersionID;
                    newRatesReportOutput.Year      = lCookieData.Year;

                    foreach (var reportItem in lRatesReportRecords)
                    {
                        recordCount++;

                        if (lRateTypeID != reportItem.RateTypeID)
                        {
                            lRateTypeID = Convert.ToInt32(reportItem.RateTypeID);

                            lAdTypeID = 0;
                            lTierID   = -1;

                            if (isTierOpen)
                            {
                                newRatesReportAdType.Tiers.Add(newRatesReportTier);
                                isTierOpen = false;
                            }

                            if (isAdTypeOpen)
                            {
                                newRatesReportRateType.AdTypes.Add(newRatesReportAdType);
                                isAdTypeOpen = false;
                            }

                            if (isRateOpen)
                            {
                                newRatesReportOutput.RateTypes.Add(newRatesReportRateType);
                                isRateOpen = false;
                            }

                            newRatesReportRateType = new RatesReportRateType
                            {
                                RateType   = reportItem.RateType,
                                RateTypeID = Convert.ToInt32(reportItem.RateTypeID)
                            };
                            isRateOpen = true;
                        }

                        // AdTypes
                        if (lAdTypeID != reportItem.AdTypeID)
                        {
                            lAdTypeID = Convert.ToInt32(reportItem.AdTypeID);

                            if (isTierOpen)
                            {
                                newRatesReportAdType.Tiers.Add(newRatesReportTier);
                                isTierOpen = false;
                            }
                            lTierID = -1;

                            if (isAdTypeOpen)
                            {
                                newRatesReportRateType.AdTypes.Add(newRatesReportAdType);
                                isAdTypeOpen = false;
                            }

                            newRatesReportAdType = new RatesReportAdType
                            {
                                ParentAdType   = reportItem.ParentAdType,
                                ParentAdTypeID = Convert.ToInt32(reportItem.ParentAdTypeID),
                                EditionType    = reportItem.EditionType,
                                EditionTypeID  = Convert.ToInt32(reportItem.EditionTypeID),
                                AdType         = reportItem.AdType,
                                AdTypeID       = Convert.ToInt32(reportItem.AdTypeID),
                            };

                            if (!String.IsNullOrEmpty(reportItem.PublisherAgreement))
                            {
                                newRatesReportAdType.PublisherAgreement = reportItem.PublisherAgreement;
                            }
                            isAdTypeOpen = true;
                        }

                        //Tiers
                        if (lTierID != reportItem.TierID)
                        {
                            lTierID = Convert.ToInt32(reportItem.TierID);

                            if (isTierOpen)
                            {
                                newRatesReportAdType.Tiers.Add(newRatesReportTier);
                                isTierOpen = false;
                            }

                            newRatesReportTier = new RatesReportTier
                            {
                                TierID    = Convert.ToInt32(reportItem.TierID),
                                TierRange = reportItem.TierRange
                            };

                            if (reportItem.Rate != null)
                            {
                                newRatesReportTier.Rate = Convert.ToDecimal(reportItem.Rate);
                            }
                            isTierOpen = true;
                        }

                        if (recordCount == recordTotal)
                        {
                            newRatesReportAdType.Tiers.Add(newRatesReportTier);
                            newRatesReportRateType.AdTypes.Add(newRatesReportAdType);
                            newRatesReportOutput.RateTypes.Add(newRatesReportRateType);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = string.Format("Error in Repository GetRatesReport method.  Publisher: {0}, Book: {1}, BookID: {2}.", lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                throw new Exception(lReturnMessage);
            }

            if (newRatesReportOutput.RateTypes.Any())
            {
                lResult = newRatesReportOutput;
            }

            return(lResult);
        }
Esempio n. 10
0
        public CirculationModel GetCirculation()
        {
            var lResult               = new CirculationModel();
            var lLogMsg               = string.Empty;
            var lCirculationOutput    = new List <CirculationModel>();
            var newCirculationOutput  = new CirculationModel();
            var newCirculationGroup   = new CirculationGroup();
            var newCirculationContent = new CirculationContent();
            var lCircGroupTable       = string.Empty;
            var pContext              = System.Web.HttpContext.Current;
            var isCircGroupOpen       = false;
            var isCircContentOpen     = false;
            var recordCount           = 0;

            // Get BookID, VersionID & Year from Cookie
            var lCookieData = CookieManagement.GetCookie(pContext);

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    var lCirculationRecords = db.GetCirculation(lCookieData.Year, lCookieData.BookID, lCookieData.VersionID)
                                              .ToList();

                    var recordTotal = lCirculationRecords.Count;

                    newCirculationOutput.BookID    = Convert.ToInt32(lCookieData.BookID);
                    newCirculationOutput.VersionID = lCookieData.VersionID;
                    newCirculationOutput.Year      = lCookieData.Year;

                    foreach (var circItem in lCirculationRecords)
                    {
                        recordCount++;

                        if (lCircGroupTable != circItem.CirculationGroupType + " " + circItem.CirculationType)
                        {
                            lCircGroupTable = circItem.CirculationGroupType + " " + circItem.CirculationType;

                            if (isCircContentOpen)
                            {
                                newCirculationGroup.CirculationContents.Add(newCirculationContent);
                                isCircContentOpen = false;
                            }

                            if (isCircGroupOpen)
                            {
                                newCirculationOutput.CirculationGroups.Add(newCirculationGroup);
                                isCircGroupOpen = false;
                            }

                            newCirculationGroup = new CirculationGroup
                            {
                                CirculationGroupType = circItem.CirculationGroupType,
                                CirculationType      = circItem.CirculationType,
                                CirculationTable     = lCircGroupTable
                            };
                            isCircGroupOpen = true;
                        }

                        // Content
                        if (isCircContentOpen)
                        {
                            newCirculationGroup.CirculationContents.Add(newCirculationContent);
                            isCircContentOpen = false;
                        }

                        newCirculationContent = new CirculationContent
                        {
                            CirculationSubType   = circItem.CirculationSubType,
                            CirculationSubTypeID = circItem.CirculationSubTypeID,
                        };

                        if (circItem.PrintCirculation != null)
                        {
                            newCirculationContent.PrintCirculation = Convert.ToInt32(circItem.PrintCirculation);
                        }
                        if (circItem.DigitalReplicaCirculation != null)
                        {
                            newCirculationContent.DigitalReplicaCirculation = Convert.ToInt32(circItem.DigitalReplicaCirculation);
                        }
                        if (circItem.DigitalNonReplicaCirculation != null)
                        {
                            newCirculationContent.DigitalNonReplicaCirculation = Convert.ToInt32(circItem.DigitalNonReplicaCirculation);
                        }
                        isCircContentOpen = true;

                        if (recordCount == recordTotal)
                        {
                            newCirculationGroup.CirculationContents.Add(newCirculationContent);
                            newCirculationOutput.CirculationGroups.Add(newCirculationGroup);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in Repository GetCirculation.  Publisher: {0}, Book: {1}, BookID: {2}.", lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                throw new Exception(lReturnMessage);
            }

            if (newCirculationOutput.CirculationGroups.Any())
            {
                lResult = newCirculationOutput;
            }

            return(lResult);
        }
Esempio n. 11
0
        public RatesModel GetRates()
        {
            var lResult         = new RatesModel();
            var lLogMsg         = string.Empty;
            var lRatesContainer = new RatesModel();
            var pContext        = System.Web.HttpContext.Current;

            // Get BookID, VersionID & Year from Cookie
            var lCookieData = CookieManagement.GetCookie(pContext);

            var newParentADType = new RateParentAdType();
            var lParentAdTypeID = 0;
            var lRateTypeID     = 0;
            var lAdTypeID       = 0;
            var lTierID         = -1;

            var isTierOpen     = false;
            var isAdOpen       = false;
            var isRateOpen     = false;
            var isParentAdOpen = false;

            var newRateRateType    = new RateRateType();
            var newRateAdType      = new RateAdType();
            var newRateTier        = new RateTier();
            var newRateEditionType = new RateEditionType();
            var recordCount        = 0;

            try
            {
                using (Loreal_DEVEntities6 db = new Loreal_DEVEntities6())
                {
                    //var lRatesData = db.GetRates("2017", 8, 1)
                    var lRatesData = db.GetRates(lCookieData.Year, lCookieData.BookID, lCookieData.VersionID)
                                     .ToList();

                    var recordTotal = lRatesData.Count;

                    lRatesContainer.PublisherName = lCookieData.Publisher;
                    lRatesContainer.BookName      = lCookieData.Book;
                    lRatesContainer.Year          = lCookieData.Year;
                    lRatesContainer.VersionID     = lCookieData.VersionID;

                    foreach (var rateItem in lRatesData)
                    {
                        recordCount++;

                        // Add class member values for new record.

                        // ParentAdType
                        if (lParentAdTypeID != rateItem.ParentAdTypeID)
                        {
                            lParentAdTypeID = Convert.ToInt32(rateItem.ParentAdTypeID);

                            /* Ready to add the populated ParentAdType to RatesModel RateParentAdTypes collection or is this the first one?
                             * Reset vars for new new ParentADType */
                            lRateTypeID = 0;
                            lAdTypeID   = 0;
                            lTierID     = -1;

                            if (isTierOpen)
                            {
                                newRateAdType.RateTiers.Add(newRateTier);
                                isTierOpen = false;
                            }

                            if (isAdOpen)
                            {
                                newRateRateType.RateAdTypes.Add(newRateAdType);
                                isAdOpen = false;
                            }
                            if (isRateOpen)
                            {
                                newParentADType.RateRateTypes.Add(newRateRateType);
                                isRateOpen = false;
                            }

                            // Make this specific to the parent
                            if (isParentAdOpen)
                            {
                                lRatesContainer.RateParentAdTypes.Add(newParentADType);
                                isParentAdOpen = false;
                            }

                            // Now add the new populated ParentADType to the Rates container
                            if (lParentAdTypeID != 0)
                            {
                                newParentADType = new RateParentAdType
                                {
                                    ParentAdTypeID = lParentAdTypeID,
                                    ParentAdType   = rateItem.ParentAdType
                                };
                                if (rateItem.AdvertorialEarnedPercentDiscount != null)
                                {
                                    newParentADType.AdvertorialEarnedPercentDiscount = rateItem.AdvertorialEarnedPercentDiscount;
                                }
                                if (rateItem.BleedOpenPercentPremium != null)
                                {
                                    newParentADType.BleedOpenPercentPremium = rateItem.BleedOpenPercentPremium;
                                }
                                if (rateItem.BleedEarnedPercentPremium != null)
                                {
                                    newParentADType.BleedEarnedPercentPremium = rateItem.BleedEarnedPercentPremium;
                                }
                                if (rateItem.Cover2OpenPercentPremium != null)
                                {
                                    newParentADType.Cover2OpenPercentPremium = rateItem.Cover2OpenPercentPremium;
                                }
                                if (rateItem.Cover2EarnedPercentPremium != null)
                                {
                                    newParentADType.Cover2EarnedPercentPremium = rateItem.Cover2EarnedPercentPremium;
                                }
                                if (rateItem.Cover3OpenPercentPremium != null)
                                {
                                    newParentADType.Cover3OpenPercentPremium = rateItem.Cover3OpenPercentPremium;
                                }
                                if (rateItem.Cover3EarnedPercentPremium != null)
                                {
                                    newParentADType.Cover3EarnedPercentPremium = rateItem.Cover3EarnedPercentPremium;
                                }
                                if (rateItem.Cover4OpenPercentPremium != null)
                                {
                                    newParentADType.Cover4OpenPercentPremium = rateItem.Cover4OpenPercentPremium;
                                }
                                if (rateItem.Cover4EarnedPercentPremium != null)
                                {
                                    newParentADType.Cover4EarnedPercentPremium = rateItem.Cover4EarnedPercentPremium;
                                }
                                if (rateItem.FracHalfPageOpenPercentPremium != null)
                                {
                                    newParentADType.FracHalfPageOpenPercentPremium = rateItem.FracHalfPageOpenPercentPremium;
                                }
                                if (rateItem.FracHalfPageEarnedPercentPremium != null)
                                {
                                    newParentADType.FracHalfPageEarnedPercentPremium = rateItem.FracHalfPageEarnedPercentPremium;
                                }
                                if (rateItem.FracThirdPageOpenPercentPremium != null)
                                {
                                    newParentADType.FracThirdPageOpenPercentPremium = rateItem.FracThirdPageOpenPercentPremium;
                                }
                                if (rateItem.FracThirdPageEarnedPercentPremium != null)
                                {
                                    newParentADType.FracThirdPageEarnedPercentPremium = rateItem.FracThirdPageEarnedPercentPremium;
                                }
                                if (rateItem.FracThirdRunOppFBPOpenPercentPremium != null)
                                {
                                    newParentADType.FracThirdRunOppFBPOpenPercentPremium = rateItem.FracThirdRunOppFBPOpenPercentPremium;
                                }
                                if (rateItem.FracThirdRunOppFBPEarnedPercentPremium != null)
                                {
                                    newParentADType.FracThirdRunOppFBPEarnedPercentPremium = rateItem.FracThirdRunOppFBPEarnedPercentPremium;
                                }
                                if (rateItem.SpreadC2P1EarnedPercentDiscount != null)
                                {
                                    newParentADType.SpreadC2P1EarnedPercentDiscount = rateItem.SpreadC2P1EarnedPercentDiscount;
                                }
                                if (rateItem.SpreadROBEarnedPercentDiscount != null)
                                {
                                    newParentADType.SpreadROBEarnedPercentDiscount = rateItem.SpreadROBEarnedPercentDiscount;
                                }
                                if (rateItem.FifthColorMetallicOpenDollarPremium != null)
                                {
                                    newParentADType.FifthColorMetallicOpenDollarPremium = rateItem.FifthColorMetallicOpenDollarPremium;
                                }
                                if (rateItem.FifthColorMetallicEarnedDollarPremium != null)
                                {
                                    newParentADType.FifthColorMetallicEarnedDollarPremium = rateItem.FifthColorMetallicEarnedDollarPremium;
                                }
                                if (rateItem.FifthColorMatchOpenDollarPremium != null)
                                {
                                    newParentADType.FifthColorMatchOpenDollarPremium = rateItem.FifthColorMatchOpenDollarPremium;
                                }
                                if (rateItem.FifthColorMatchEarnedDollarPremium != null)
                                {
                                    newParentADType.FifthColorMatchEarnedDollarPremium = rateItem.FifthColorMatchEarnedDollarPremium;
                                }
                                if (rateItem.FifthColorPMSOpenDollarPremium != null)
                                {
                                    newParentADType.FifthColorPMSOpenDollarPremium = rateItem.FifthColorPMSOpenDollarPremium;
                                }
                                if (rateItem.FifthColorPMSEarnedDollarPremium != null)
                                {
                                    newParentADType.FifthColorPMSEarnedDollarPremium = rateItem.FifthColorPMSEarnedDollarPremium;
                                }
                                isParentAdOpen = true;
                            }
                        }
                        // RateType
                        if (lRateTypeID != rateItem.RateTypeID)
                        {
                            lRateTypeID = Convert.ToInt32(rateItem.RateTypeID);

                            if (isTierOpen)
                            {
                                newRateAdType.RateTiers.Add(newRateTier);
                                isTierOpen = false;
                            }

                            if (isAdOpen)
                            {
                                newRateRateType.RateAdTypes.Add(newRateAdType);
                                isAdOpen = false;
                            }

                            if (isRateOpen)
                            {
                                newParentADType.RateRateTypes.Add(newRateRateType);
                                isRateOpen = false;
                            }

                            lAdTypeID = 0;
                            lTierID   = -1;
                            if (lRateTypeID != 0)
                            {
                                newRateRateType = new RateRateType
                                {
                                    RateTypeName = rateItem.RateType,
                                    RateTypeID   = lRateTypeID
                                };
                                isRateOpen = true;
                            }
                        }

                        // AdType
                        if (lAdTypeID != rateItem.AdTypeID)
                        {
                            lAdTypeID = Convert.ToInt32(rateItem.AdTypeID);

                            if (isTierOpen)
                            {
                                newRateAdType.RateTiers.Add(newRateTier);
                                isTierOpen = false;
                            }
                            lTierID = -1;

                            if (isAdOpen)
                            {
                                newRateRateType.RateAdTypes.Add(newRateAdType);
                                isAdOpen = false;
                            }

                            if (lAdTypeID != 0)
                            {
                                newRateAdType = new RateAdType
                                {
                                    AdType   = rateItem.AdType,
                                    AdTypeID = lAdTypeID
                                };
                                if (rateItem.PublisherAgreement != null)
                                {
                                    newRateAdType.PublisherAgreement = rateItem.PublisherAgreement;
                                }
                                isAdOpen = true;
                            }
                        }

                        // Tier
                        if (lTierID != rateItem.TierID)
                        {
                            lTierID = Convert.ToInt32(rateItem.TierID);

                            if (isTierOpen)
                            {
                                newRateAdType.RateTiers.Add(newRateTier);
                                isTierOpen = false;
                            }

                            newRateTier = new RateTier
                            {
                                Tier      = rateItem.Tier,
                                TierRange = rateItem.TierRange,
                                TierID    = lTierID
                            };
                            isTierOpen = true;
                        }

                        // EditionType
                        newRateEditionType = new RateEditionType();
                        // Only add a class member if the record has a value.  Otherwise, leave out to preserve NULL.
                        if (rateItem.EditionTypeID != null)
                        {
                            newRateEditionType.EditionTypeID = Convert.ToInt32(rateItem.EditionTypeID);
                        }
                        if (!String.IsNullOrEmpty(rateItem.EditionType))
                        {
                            newRateEditionType.EditionTypeName = rateItem.EditionType;
                        }
                        if (rateItem.Rate != null)
                        {
                            newRateEditionType.Rate = Convert.ToDecimal(rateItem.Rate);
                        }
                        if (rateItem.CPM != null)
                        {
                            newRateEditionType.CPM = Convert.ToDecimal(rateItem.CPM);
                        }
                        if (rateItem.RateBaseCirculationGuarantee != null)
                        {
                            newRateEditionType.RateBaseCirculationGuarantee = Convert.ToDecimal(rateItem.RateBaseCirculationGuarantee / 1000.00); // For display
                        }
                        if (rateItem.AveragePrintRun != null)
                        {
                            newRateEditionType.AveragePrintRun = Convert.ToDecimal(rateItem.AveragePrintRun / 1000.00); // For display
                        }
                        if (rateItem.OpenProductionCost != null)
                        {
                            newRateEditionType.OpenProductionCost = Convert.ToInt32(rateItem.OpenProductionCost);
                        }
                        if (rateItem.EarnedProductionCost != null)
                        {
                            newRateEditionType.EarnedProductionCost = Convert.ToInt32(rateItem.EarnedProductionCost);
                        }
                        if (rateItem.EarnedNEP != null)
                        {
                            newRateEditionType.EarnedNEP = Convert.ToDecimal(rateItem.EarnedNEP);
                        }

                        newRateTier.RateEditionTypes.Add(newRateEditionType);

                        if (recordCount == recordTotal)
                        {
                            newRateAdType.RateTiers.Add(newRateTier);
                            newRateRateType.RateAdTypes.Add(newRateAdType);
                            newParentADType.RateRateTypes.Add(newRateRateType);
                            lRatesContainer.RateParentAdTypes.Add(newParentADType);
                        }
                    }

                    if (lRatesContainer.RateParentAdTypes.Any())
                    {
                        lResult = lRatesContainer;
                    }

                    return(lResult);
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in Repository GetRates method.  BookID: {0}.", lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}. INNER EXCEPTION: {1}  SOURCE: {2}. STACKTRACE: {3}.", ex.Message, ex.InnerException, ex.Source, ex.StackTrace);

                if (ex.InnerException != null)
                {
                    if (((System.Data.SqlClient.SqlException)ex.InnerException).Procedure != null)
                    {
                        var lSQLError = String.Format("SQL ERROR INFORMATION: PROCEDURE: {0}.  LINE NUMBER: {1}.", ((System.Data.SqlClient.SqlException)ex.InnerException).Procedure, ((System.Data.SqlClient.SqlException)ex.InnerException).LineNumber);
                        lLogMsg = lSQLError + lLogMsg;
                    }
                }
                logger.Error(lLogMsg);
                throw new Exception(lReturnMessage);
            }
        }