Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        internal static VersionInfoModel SaveBookInfoToCookie(int pBookID, IPrincipal pUser)
        {
            // Get BookID, VersionID & Year from Cookie
            var lLogMsg      = string.Empty;
            var pContext     = HttpContext.Current;
            var lCookieData  = CookieManagement.GetCookie(pContext);
            var lVersionInfo = new VersionInfoModel();
            var lYear        = lCookieData.Year;
            var cookieData   = new CustomPrincipalSerializerModel();

            try
            {
                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    var lBook = db.Books
                                .Where(b => b.BookID == pBookID && b.Year == lYear).SingleOrDefault();

                    // Get Version and Status information; Update cookie with this and pass back to client.
                    var lVersions = GetVersionInfo(pBookID, lYear);
                    if (lVersions.Any())
                    {
                        lVersions = lVersions.OrderByDescending(v => v.VersionID).ToList();
                    }
                    var lLatestVersion = lVersions.FirstOrDefault();

                    // Update Cookie
                    cookieData.BookID    = pBookID;
                    cookieData.Book      = lBook.Book1;
                    cookieData.VersionID = lLatestVersion.VersionID;
                    cookieData.Status    = lLatestVersion.Status;

                    var lbool = CookieManagement.UpdateCookie(HttpContext.Current, pUser, cookieData);

                    // Populate VersionInfoModel
                    lVersionInfo.Status      = lLatestVersion.Status;
                    lVersionInfo.VersionID   = lLatestVersion.VersionID;
                    lVersionInfo.VersionList = lVersions;
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in SaveBookInfoToCookie.  BookID: {0}, User: {1}.", pBookID, pUser.Identity.Name);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }
            return(lVersionInfo);
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetBookYears()
        {
            IHttpActionResult lResult = null;
            var lLogMsg  = string.Empty;
            var lstYears = new BooksViewModel().Years;

            try
            {
                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    var years = db.Books
                                .Select(b => b.Year)
                                .Distinct()
                                .ToList();

                    if (years.Any())
                    {
                        foreach (var item in years)
                        {
                            var bkYear = new BookYear();
                            bkYear.Year   = item;
                            bkYear.YearId = Convert.ToInt16(item);
                            lstYears.Add(bkYear);
                        }

                        lResult = Ok(lstYears);
                    }
                    else
                    {
                        lResult = Ok();
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetBookYears.");
                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);
        }
Ejemplo n.º 4
0
        internal static string GetPublisher(int?pPublisherID)
        {
            var lLogMsg    = string.Empty;
            var lPublisher = string.Empty;

            try
            {
                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    lPublisher = db.Publishers
                                 .Where(p => p.PublisherID == pPublisherID)
                                 .Select(p => p.Publisher1)
                                 .FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetPublisher for PublisherID: {0}.", pPublisherID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }
            return(lPublisher);
        }
Ejemplo n.º 5
0
        internal static List <BookToVersion> GetVersionInfo(int pBookID, string pYear)
        {
            var          lLogMsg      = string.Empty;
            var          lBookVersion = new List <BookToVersion>();
            const string STATUS       = "In Progress";

            try
            {
                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    lBookVersion = db.BookToVersions
                                   .Where(a => a.BookID == pBookID && a.Year == pYear)
                                   .ToList();

                    if (!lBookVersion.Any())
                    {
                        // Call CreateNewVersion SP
                        var lVersionNum = db.CreateNewVersion(pYear, pBookID);
                        var lBook       = new BookToVersion
                        {
                            BookID    = pBookID,
                            VersionID = lVersionNum,
                            Year      = pYear,
                            Status    = STATUS
                        };
                        lBookVersion.Add(lBook);
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetVersionInfo.  BookID: {0}, Year: {1}.", pBookID, pYear);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
            }
            return(lBookVersion);
        }
Ejemplo n.º 6
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);
        }