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 void Put(int id, [FromBody] string value)
        {
            // Get BookID, VersionID & Year from Cookie
            var pContext = System.Web.HttpContext.Current;
            var lLogMsg  = string.Empty;
            var lName    = String.Empty;

            // Update Cookie
            var lCookieData = new CustomPrincipalSerializerModel();

            lCookieData.Book   = lName;
            lCookieData.BookID = id;

            try
            {
                // Get Book Name
                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    lName = db.Books
                            .Where(b => b.BookID == id)
                            .Select(B => B.Book1).FirstOrDefault();
                }

                var lbool = CookieManagement.UpdateCookie(System.Web.HttpContext.Current, User, lCookieData);
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in saveBook (Book Put).  BOOK: {0}, Publisher: {1}.", lCookieData.Publisher, id);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 5
0
        public ActionResult GeneratePDFOutput()
        {
            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);
            var lLogMsg     = string.Empty;
            var pdfService  = new PDFService();

            try
            {
                // Print Output for given BookID
                var pdfModel = new PDFDocumentModel
                {
                    Book        = lCookieData.Book,
                    BookID      = Convert.ToInt32(lCookieData.BookID),
                    Publisher   = lCookieData.Publisher,
                    PublisherID = Convert.ToInt32(lCookieData.PublisherID),
                    VersionID   = lCookieData.VersionID,
                    Year        = lCookieData.Year
                };

                var lResult = pdfService.BuildPDF(pdfModel, pContext);

                if (lResult.Any())
                {
                    // Set Up the Response Stream for the Spec Sheet Collection
                    System.Web.HttpContext.Current.Response.Clear();
                    System.Web.HttpContext.Current.Response.BufferOutput = false;
                    System.Web.HttpContext.Current.Response.ContentType  = "application/pdf";
                    System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + "loreal_output.pdf");
                    // Create a FileStream for the PDF and Send it to the Response's OutputStream
                    using (var outStream = new FileStream(pdfService.FilePath, FileMode.Open))
                    {
                        byte[] buffer = new byte[4096];
                        int    count  = 0;
                        while ((count = outStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            System.Web.HttpContext.Current.Response.OutputStream.Write(buffer, 0, count);
                            System.Web.HttpContext.Current.Response.Flush();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in PrintPDFOutput.  BOOK: {0}, Publisher: {1}.", lCookieData.Book, lCookieData.Publisher);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }

            return(View());
        }
Esempio n. 6
0
        public ActionResult LogOff()
        {
            // Log user logged out.
            var lUserName = System.Web.HttpContext.Current.User.Identity.GetUserName();
            var lLogMsg   = String.Format("USER: {0} just logged OUT.", lUserName);

            logger.Info(lLogMsg);

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            var lResult = CookieManagement.DeleteCookie(System.Web.HttpContext.Current);

            return(RedirectToAction("Login", "Account"));
        }
Esempio n. 7
0
        //public HttpResponseMessage PrintPDFOutput()
        //public System.Web.Mvc.ActionResult PrintPDFOutput()
        public IHttpActionResult PrintPDFOutput()
        {
            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);
            var lLogMsg     = string.Empty;
            var pdfService  = new PDFService();

            try
            {
                // Print Output for given BookID
                var pdfModel = new PDFDocumentModel
                {
                    Book        = lCookieData.Book,
                    BookID      = Convert.ToInt32(lCookieData.BookID),
                    Publisher   = lCookieData.Publisher,
                    PublisherID = Convert.ToInt32(lCookieData.PublisherID),
                    VersionID   = lCookieData.VersionID,
                    Year        = lCookieData.Year
                };

                var lResult = pdfService.BuildPDF(pdfModel, pContext);

                if (lResult.Any())
                {
                    // Set up the Response Stream for the File
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ClearHeaders();
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.Expires = -1000;
                    //HttpContext.Current.Response.BufferOutput = false;
                    HttpContext.Current.Response.ContentType = "application/pdf";
                    HttpContext.Current.Response.AddHeader("content-length", lResult.Length.ToString());
                    HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=" + "loreal_output.pdf");
                    HttpContext.Current.Response.BinaryWrite(lResult);
                    HttpContext.Current.Response.End();
                }

                //}
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in PrintPDFOutput.  BOOK: {0}, Publisher: {1}.", lCookieData.Book, lCookieData.Publisher);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }

            return(Ok(HttpContext.Current.Response));
        }
Esempio n. 8
0
        public IHttpActionResult saveAnswers(List <Answer> answers)
        {
            // Get BookID, VersionID & Year from Cookie
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            IHttpActionResult lResult = null;
            var lLogMsg         = string.Empty;
            var lAnswerIDs      = new List <string>();
            var lAnswerIDsArray = lAnswerIDs.ToArray();

            try
            {
                foreach (var answer in answers)
                {
                    answer.BookID    = Convert.ToInt32(lCookieData.BookID);
                    answer.VersionID = lCookieData.VersionID < 1 ? 1 : lCookieData.VersionID;
                    answer.Year      = lCookieData.Year;
                    answer.Load_Date = DateTime.Now;
                    string lID = Save(answer);
                    lAnswerIDs.Add(lID);
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in saveAnswers.  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 (lAnswerIDs.Any())
            {
                lResult = Ok(lAnswerIDs);
            }
            else if (lAnswerIDs.Contains("-1"))
            {
                lResult = BadRequest();
            }
            else
            {
                lResult = Ok();
            }

            return(lResult);
        }
Esempio n. 9
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                // Create cookie
                CookieManagement.CreateCookie(System.Web.HttpContext.Current, User, model.Email);

                // Log user logged in.
                var lLogMsg = String.Format("USER: {0} just logged IN.", model.Email);
                logger.Info(lLogMsg);

                if (String.IsNullOrEmpty(returnUrl))
                {
                    returnUrl = "/print/books";
                }

                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Esempio n. 10
0
        public IHttpActionResult GetAnswers()
        {
            IHttpActionResult lResult = null;
            var lLogMsg    = string.Empty;
            var lstAnswers = new List <Answer>();
            var pContext   = System.Web.HttpContext.Current;

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

            try
            {
                using (Loreal_DEVEntities3 db = new Loreal_DEVEntities3())
                {
                    lstAnswers = db.Answers
                                 .Where(a => a.BookID == lCookieData.BookID && a.Year == lCookieData.Year && a.VersionID == lCookieData.VersionID)
                                 .ToList();
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetAnswers.  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 (lstAnswers.Any())
            {
                lResult = Ok(lstAnswers);
            }
            else
            {
                lResult = Ok();
            }

            return(lResult);
        }
Esempio n. 11
0
        // GET api/<controller>
        public IHttpActionResult Get()
        {
            // Update Cookie wth bookID
            var pContext    = System.Web.HttpContext.Current;
            var lCookieData = CookieManagement.GetCookie(pContext);

            CookieManagement.SaveBookInfoToCookie(Convert.ToInt32(lCookieData.BookID), User);

            IHttpActionResult lResult = null;
            var           lLogMsg     = string.Empty;
            QuestionModel vm          = new QuestionModel();

            vm.Get(System.Web.HttpContext.Current);
            if (vm.SectionsListModel.SectionList.Any())
            {
                lResult = Ok(vm.SectionsListModel.SectionList);
            }
            else
            {
                lResult = Ok();
            }
            return(lResult);
        }
Esempio n. 12
0
        public ActionResult Index()
        {
            var isauthCookie     = false;
            var isResponseCookie = false;

            // If user is already logged in (They have a cookie) take them straight to the Book page.
            var returnUrl  = "";
            var authCookie = HttpContext.Request.Cookies["lorealPrint"];

            if (authCookie == null)
            {
                returnUrl = "/Account/Login";
            }
            if (authCookie != null)
            {
                isauthCookie     = !String.IsNullOrEmpty(authCookie.Value);
                isResponseCookie = (HttpContext.Response.Cookies["lorealPrint"] != null);

                if (isauthCookie)
                {
                    returnUrl = "/print/books";
                    //return Redirect(returnUrl);
                }
                else if (!isauthCookie && isResponseCookie)
                {
                    /*  We're in a zombie state.  First loggoff user (which will delete cookie).
                     *  This, in turn, will then redirect the user to the login page. */
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

                    var lResult = CookieManagement.DeleteCookie(System.Web.HttpContext.Current);

                    return(RedirectToAction("Login", "Account"));
                }
            }
            return(Redirect(returnUrl));
        }
        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. 14
0
        public void Get(System.Web.HttpContext pContext)
        {
            const string YES         = "Yes";
            var          lCookieData = CookieManagement.GetCookie(pContext);

            /* BUG found by Negmat.  If user changes book this isn't getting updated.
             * Added ResetDynamicValues method to reset AvgVerifiedCircPercent and Genre values in case the user was
             * previously working with another book in the same session. */
            ResetDynamicValues();

            using (Loreal_DEVEntities3 db = new Loreal_DEVEntities3())
            {
                var questionsList = new List <QuestionModel>();
                var IsDynamic     = false;

                // Get the Questions from the database.
                var lQuestions = db.GetAnswers(lCookieData.Year, lCookieData.BookID, lCookieData.VersionID)
                                 .OrderBy(q => q.SectionOrder)
                                 .ThenBy(q => q.SubSectionOrder)
                                 .ThenBy(q => q.SubSectionToQuestionOrder)
                                 .ToList();

                var IsParent         = false;
                var newSectionList   = new QuestionSectionsListModel();
                var newSection       = new QuestionSectionModel();
                var newSubSection    = new QuestionSubSectionModel();
                var newQuestion      = new QuestionModel();
                var newChildQuestion = new QuestionChildModel();
                var QuestName        = string.Empty;
                var SubSecName       = string.Empty;
                var SecName          = string.Empty;
                var recordCount      = 0;
                var recordTotal      = lQuestions.Count;

                /* Data is ordered so that the first item in the collection should be a Question (as opposed to a child question.
                 * This means the first record will contain:
                 * 1.  A new Section
                 * 2.  A new SubSection
                 * 3.  A new Question
                 * All subsequent records may either be contained within an existing Question, SubSection and/or Section.
                 * Thus the way this is structured below. */

                foreach (var question in lQuestions)
                {
                    recordCount++;
                    // We work our way out from Child Question to Section.
                    IsParent = question.IsTopLevel == YES ? true : false;

                    /* If the current Question is a Parent and there is a previous Question we now add it to the Question List.
                     * (Otherwise, the current question is a Child question and we will continue to add Children to the question
                     * until the next Parent question. */
                    if ((IsParent && newQuestion.ID > 0) || (!IsParent && SubSecName != question.SubSection))
                    {
                        newSubSection.QuestionList.Add(newQuestion);
                    }

                    // If the Section is new the SubSection and Question are, by default, new as well.
                    if (String.IsNullOrEmpty(SecName) || (SecName != question.Section))
                    {
                        if (!String.IsNullOrEmpty(SecName))
                        {
                            // First add the existing SubSection to the existing Section
                            newSection.SubSectionList.Add(newSubSection);
                            // Add the existing Section to the SectionList prior to creating the new Section.
                            newSectionList.SectionList.Add(newSection);
                        }

                        newSection = new QuestionSectionModel
                        {
                            ID    = question.SectionID,
                            Name  = question.Section,
                            Order = question.SectionOrder
                        };
                        SecName = question.Section;

                        newSubSection = new QuestionSubSectionModel
                        {
                            ID    = question.SubSectionID,
                            Name  = question.SubSection,
                            Order = question.SubSectionOrder
                        };
                        SubSecName = question.SubSection;
                    }
                    else if (SecName == question.Section && (SubSecName != question.SubSection))
                    {
                        // First, add the existing SubSection to the Section.
                        newSection.SubSectionList.Add(newSubSection);

                        newSubSection = new QuestionSubSectionModel
                        {
                            ID    = question.SubSectionID,
                            Name  = question.SubSection,
                            Order = question.SubSectionOrder
                        };
                        SubSecName = question.SubSection;
                    }

                    // Question/Child question
                    if (!IsParent)
                    {
                        IsDynamic = (question.QuestionType == DYNSTATEMENT || question.QuestionType == DYNYESNO);

                        // Resolve Dynamic Questions
                        if (IsDynamic)
                        {
                            // Temp for testing
                            var lBookID = lCookieData.BookID == null ? 8 : lCookieData.BookID;

                            if (String.IsNullOrEmpty(Dynamic.AvgVerifiedCircPercent))
                            {
                                GetDynamicValues(lBookID, lCookieData.Year);
                            }
                            QuestName = DynamicQuestion(question.Question);
                        }
                        else
                        {
                            QuestName = question.Question;
                        }

                        newChildQuestion = new QuestionChildModel
                        {
                            ID             = question.QuestionID,
                            ParentID       = question.ParentQuestionID,
                            Name           = QuestName,
                            QuestionType   = question.QuestionType,
                            AnswerType     = question.AnswerType,
                            AnswerYesNo    = question.AnswerYesNo,
                            AnswerFreeForm = question.AnswerFreeForm
                        };
                        newQuestion.QuestionChildrenList.Add(newChildQuestion);
                    }
                    else
                    {
                        IsDynamic = (question.QuestionType == DYNSTATEMENT || question.QuestionType == DYNYESNO);

                        // Resolve Dynamic Questions
                        if (IsDynamic)
                        {
                            // Temp for testing
                            var lBookID = lCookieData.BookID == null ? 8 : lCookieData.BookID;

                            if (String.IsNullOrEmpty(Dynamic.AvgVerifiedCircPercent))
                            {
                                GetDynamicValues(lBookID, lCookieData.Year);
                            }
                            QuestName = DynamicQuestion(question.Question);
                        }
                        else
                        {
                            QuestName = question.Question;
                        }

                        newQuestion = new QuestionModel
                        {
                            ID             = question.QuestionID,
                            Order          = question.SubSectionToQuestionOrder,
                            Name           = QuestName,
                            QuestionType   = question.QuestionType,
                            AnswerYesNo    = question.AnswerYesNo,
                            AnswerFreeForm = question.AnswerFreeForm
                        };
                    }

                    // Insert final question.
                    if (recordCount == recordTotal)
                    {
                        // Is this a child question?
                        if (IsParent && newQuestion.ID > 0)
                        {
                            newSubSection.QuestionList.Add(newQuestion);
                        }
                        else
                        {
                            newSubSection.QuestionList.Add(newQuestion);
                        }
                        // Add final question to SubSection and Section Lists.
                        newSection.SubSectionList.Add(newSubSection);
                        newSectionList.SectionList.Add(newSection);

                        SectionsListModel = newSectionList;
                    }
                }
            }
        }
Esempio n. 15
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);
        }
Esempio n. 16
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;
        }
Esempio n. 17
0
        /// <summary>
        /// POSTメソッドのコア
        /// </summary>
        /// <param name="postString">送信するテキストデータ</param>
        /// <returns>返送データ</returns>
        private string PostStringCore(string postString)
        {
            bool isHostCookie = false;

            //weq.Credentials = new NetworkCredential("test", "test");
            System.Text.Encoding enc = System.Text.Encoding.GetEncoding(Encoding);
            byte[] postByte          = enc.GetBytes(postString);
            int    byteCount         = postByte.Length;

            weq.Headers.Add(ReqHeaders);
            weq.Headers.Add(HttpRequestHeader.ContentEncoding, Encoding);
            weq.UserAgent = UserAgent;
            weq.Referer   = Referer;
            //if (Host != String.Empty)
            //    weq.Host = Host;
            if (Proxy != null)
            {
                weq.Proxy = Proxy;
            }
            if (Cookies != null)
            {
                CookieContainer cc = new CookieContainer();
                foreach (Cookie item in Cookies)
                {
                    cc.Add(item);
                }
                weq.CookieContainer = cc;
            }
            if (IsReadCookieFromHost == true && Host != String.Empty && Cookies == null)
            {
                isHostCookie = true;
            }
            if (isHostCookie)
            {
                CookieContainer cc = new CookieContainer();
                foreach (Cookie item in CookieManagement.ReadCookieFromDisk())
                {
                    cc.Add(new Cookie(item.Name, item.Value, "/", item.Domain));
                }
                weq.CookieContainer = cc;
            }
            weq.Method        = "POST";
            weq.ContentLength = byteCount;
            weq.ContentType   = "application/x-www-form-urlencoded";
            Log.Logger.WriteLog("Start Http PostRequest: " + this.requestUrl);
            Stream s = weq.GetRequestStream();

            s.Write(postByte, 0, byteCount);
            System.Threading.Thread.Sleep(50);
            s.Dispose();
            wep = (HttpWebResponse)weq.GetResponse();

            if (Cookies != null)
            {
                Cookies.Add(wep.Cookies);
            }
            if (isHostCookie)
            {
                CookieManagement.WriteCookieToDisk(wep.Cookies);
            }
            Headers = wep.Headers;
            Stream ss = wep.GetResponseStream();

            Log.Logger.WriteLog("HTTP/1.1 " + wep.StatusCode.ToString());
            //weq.Abort();
            return(new StreamReader(ss, System.Text.Encoding.GetEncoding(Encoding)).ReadToEnd());
        }
Esempio n. 18
0
        public IHttpActionResult GetBooks(string year)
        {
            IHttpActionResult lResult = null;
            var lLogMsg     = string.Empty;
            var lstBooks    = new List <BookViewModel>();
            var userId      = User.Identity.GetUserId();
            int?publisherID = 0;
            var lCookieData = new CustomPrincipalSerializerModel();

            try
            {
                using (Loreal_DEVEntities5 db = new Loreal_DEVEntities5())
                {
                    publisherID = db.AspNetUsers
                                  .Where(a => a.Id == userId)
                                  .Select(a => a.PublisherID)
                                  .SingleOrDefault();
                }

                // Update Cookie
                lCookieData.Id          = userId;
                lCookieData.Year        = year;
                lCookieData.PublisherID = publisherID;
                lCookieData.Publisher   = CookieManagement.GetPublisher(publisherID);
                var lbool = CookieManagement.UpdateCookie(System.Web.HttpContext.Current, User, lCookieData);

                // We're in a weird zombie cookie state.  Logoff.
                //if (!lbool)
                //{
                //    //return Redirect("/Account/LogOff");
                //    var newUrl = this.Url.Link("Default", new
                //    {
                //        Controller = "Account",
                //        Action = "LogOff"
                //    });
                //    return Request.CreateResponse(HttpStatusCode.OK, new { Success = true, RedirectUrl = newUrl });
                //}

                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    var books = db.Books
                                .Where(b => b.Year == year && b.PublisherID == publisherID)
                                .OrderBy(b => b.Book1)
                                .ToList();

                    if (books.Any())
                    {
                        foreach (var book in books)
                        {
                            var lbook = new BookViewModel();
                            lbook.ID   = book.BookID;
                            lbook.Name = book.Book1;

                            lstBooks.Add(lbook);
                        }
                        lResult = Ok(lstBooks);
                    }
                    else
                    {
                        lResult = Ok();
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetBooks. Year: {0} Publisher: {1}, Book: {2}, BookID: {3}.", year, 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);
            }
            return(lResult);
        }
Esempio n. 19
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. 20
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);
        }
Esempio n. 21
0
        /// <summary>
        /// GETメソッドのコア
        /// </summary>
        /// <returns>取得したデータ</returns>
        private string GetStringCore()
        {
            try
            {
                weq = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
                bool isHostCookie = false;
                if (this.Range != 0)
                {
                    weq.AddRange(this.Range);
                }
                weq.Headers.Add(HttpRequestHeader.ContentEncoding, Encoding);
                weq.UserAgent = UserAgent;
                //失敬
                weq.Credentials = new NetworkCredential("test", "test");
                if (Host != String.Empty)
                {
                    weq.Host = Host;
                }
                weq.Referer = Referer;
                weq.Headers.Add(ReqHeaders);
                if (Proxy != null)
                {
                    weq.Proxy = Proxy;
                }
                if (Cookies != null)
                {
                    CookieContainer cc = new CookieContainer();
                    foreach (Cookie item in Cookies)
                    {
                        cc.Add(item);
                    }
                    weq.CookieContainer = cc;
                }
                if (IsReadCookieFromHost == true && Host != String.Empty && Cookies == null)
                {
                    isHostCookie = true;
                }
                weq.Method = "GET";
                if (isHostCookie)
                {
                    CookieContainer  c  = new CookieContainer();
                    CookieCollection cc = CookieManagement.ReadCookieFromDisk();
                    foreach (Cookie item in cc)
                    {
                        c.Add(item);
                    }
                    weq.CookieContainer = c;
                }
                Log.Logger.WriteLog("Start Http GetRequest: " + this.requestUrl);
                wep = (HttpWebResponse)weq.GetResponse();
                if (Cookies != null)
                {
                    Cookies.Add(wep.Cookies);
                }
                if (isHostCookie)
                {
                    CookieManagement.WriteCookieToDisk(wep.Cookies);
                }

                Headers = wep.Headers;
                if (wep.StatusCode == HttpStatusCode.NotModified)
                {
                    return(String.Empty);
                }
                this.RequestStatusCode = wep.StatusCode;
                Log.Logger.WriteLog("HTTP/1.1 " + this.RequestStatusCode.ToString());
                return(new StreamReader(wep.GetResponseStream(), System.Text.Encoding.GetEncoding(Encoding)).ReadToEnd());
            }
            catch (WebException e)
            {
                this.RequestStatusCode = ((HttpWebResponse)e.Response).StatusCode;
                return(null);
                //throw;
            }

            // return new StreamReader(((HttpWebResponse)weq.GetResponse()).GetResponseStream(),System.Text.Encoding.GetEncoding(Encoding)).ReadToEnd();
        }
Esempio n. 22
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);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// データをダウンロードするGETメソッドのコア
        /// </summary>
        /// <returns>取得したデータ</returns>
        private Stream GetBinaryDataCore()
        {
            try
            {
                weq = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
                bool isHostCookie = false;
                if (this.Range != 0)
                {
                    weq.AddRange(this.Range);
                }
                weq.Headers.Add(HttpRequestHeader.ContentEncoding, Encoding);
                weq.UserAgent = UserAgent;
                if (Host != String.Empty)
                {
                    weq.Host = Host;
                }
                weq.Referer = Referer;
                weq.Headers.Add(ReqHeaders);
                if (Proxy != null)
                {
                    weq.Proxy = Proxy;
                }
                if (Cookies != null)
                {
                    CookieContainer cc = new CookieContainer();
                    foreach (Cookie item in Cookies)
                    {
                        cc.Add(item);
                    }
                    weq.CookieContainer = cc;
                }
                if (IsReadCookieFromHost == true && Host != String.Empty && Cookies == null)
                {
                    isHostCookie = true;
                }
                weq.Method = "GET";
                if (isHostCookie)
                {
                    CookieContainer  c  = new CookieContainer();
                    CookieCollection cc = CookieManagement.ReadCookieFromDisk();
                    foreach (Cookie item in cc)
                    {
                        c.Add(item);
                    }
                    weq.CookieContainer = c;
                }
                wep = (HttpWebResponse)weq.GetResponse();
                if (Cookies != null)
                {
                    Cookies.Add(wep.Cookies);
                }
                if (isHostCookie)
                {
                    CookieManagement.WriteCookieToDisk(wep.Cookies);
                }

                Headers = wep.Headers;
                if (wep.StatusCode == HttpStatusCode.NotModified)
                {
                    throw new WebException();
                }
                this.RequestStatusCode = wep.StatusCode;
                return(wep.GetResponseStream());
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 24
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);
        }