예제 #1
0
        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();
            }
        }
        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);
        }
예제 #4
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);
        }
예제 #5
0
        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;
        }