Beispiel #1
0
        public AuthorModel(int mainId, int?authorId)
        {
            MainId  = mainId;
            Authors = AuthorObject.GetAuthors(MainId);

            if (authorId.HasValue)
            {
                var author = AuthorObject.GetAuthor(authorId.Value);
                if (author != null)
                {
                    AuthorId            = author.AuthorId;
                    Affiliation         = author.Affiliation;
                    AuthorName          = author.Name;
                    AuthorOrcidId       = author.OrcidId;
                    IsPrimary           = author.IsPrimary;
                    AffiliationType     = author.AffiliationEnum;
                    AffiliateEmployeeId = author.EmployeeId;
                    CountryId           = author.CountryId ?? Helper.UnitedStatesCountryId;
                    StateId             = author.StateId;
                }
            }
            else
            {
                CountryId = Helper.UnitedStatesCountryId;
            }
        }
Beispiel #2
0
        public ActionResult GetAuthorListPartial(int?id)
        {
            var model = new List <AuthorObject>();

            if (id.HasValue)
            {
                model = AuthorObject.GetAuthors(id.Value);
            }

            return(PartialView("Partials/_authorList", model));
        }
Beispiel #3
0
        [HttpPost]/*, ValidateAntiForgeryToken]*/
        public ActionResult AddAuthor(AuthorModel model)
        {
            if (ModelState.IsValid && SortMainObject.CheckUserHasWriteAccess(model.SortMainId))
            {
                model.Save();

                return(PartialView("Partials/_authorList", AuthorObject.GetAuthors(model.SortMainId)));
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(null);
        }
Beispiel #4
0
        public ActionResult GetAuthorPartial(int?id)
        {
            if (id.HasValue)
            {
                var author = AuthorObject.GetAuthor(id.Value);
                if (author != null)
                {
                    return(PartialView("Partials/AuthorsPartial", new AuthorModel(author)));
                }
            }

            return(null);
        }
Beispiel #5
0
 public AuthorModel(AuthorObject author)
 {
     if (author != null)
     {
         SortMainId          = author.SortMainId;
         AuthorId            = author.AuthorId;
         Affiliation         = author.Affiliation;
         AuthorName          = author.FullName;
         AuthorOrcidId       = author.OrcidId;
         IsPrimary           = author.IsPrimary;
         AffiliationType     = author.AffiliationEnum;
         AffiliateEmployeeId = author.EmployeeId;
         Authors             = AuthorObject.GetAuthors(SortMainId);
     }
 }
Beispiel #6
0
        private static void PopulateDatabase(QuotableContext context)
        {
            var author1 = new AuthorObject()
            {
                FirstName = "Hermione",
                LastName  = "Granger"
            };
            var author2 = new AuthorObject()
            {
                FirstName = "Albus",
                LastName  = "Dumbledore"
            };
            var author3 = new AuthorObject()
            {
                FirstName = "Harry",
                LastName  = "Potter"
            };

            var quote1 = new QuoteObject();

            quote1.Quote = "Fear of a name only increases fear of the thing itself.";

            var quote2 = new QuoteObject();

            quote2.Quote = "It is our choices, Harry, that show what we truly are, far more than our abilities.";

            var quote3 = new QuoteObject();

            quote3.Quote = "I solemnly swear I am up to no good.";

            var qa1 = new QuotesAndAuthorsObject()
            {
                Quote = quote1, Author = author1
            };
            var qa2 = new QuotesAndAuthorsObject()
            {
                Quote = quote2, Author = author2
            };
            var qa3 = new QuotesAndAuthorsObject()
            {
                Quote = quote3, Author = author3
            };

            context.AddRange(qa1, qa2, qa3);

            context.SaveChanges();
        }
Beispiel #7
0
        public ActionResult SetPrimaryAuthor(int?id)
        {
            int mid = 0;

            if (id.HasValue)
            {
                var author = AuthorObject.GetAuthor(id.Value);
                if (author != null)
                {
                    mid = author.MainId;
                    if (MainObject.CheckUserHasWriteAccess(mid))
                    {
                        author.SetAsPrimary();
                    }
                }
            }

            return(GetAuthorListPartial(mid));
        }
Beispiel #8
0
        public ActionResult SetPrimaryAuthor(int?id)
        {
            int sid = 0;

            if (id.HasValue)
            {
                var author = AuthorObject.GetAuthor(id.Value);
                if (author != null)
                {
                    sid = author.SortMainId;
                    if (SortMainObject.CheckUserHasWriteAccess(sid))
                    {
                        author.SetAsPrimary();
                    }
                }
            }

            return(PartialView("Partials/_authorList", AuthorObject.GetAuthors(sid)));
        }
Beispiel #9
0
 public void Save()
 {
     if (MainId > 0)
     {
         if (AuthorId.HasValue)
         {
             var author = AuthorObject.GetAuthor(AuthorId.Value);
             if (author != null)
             {
                 author.AffiliationEnum = AffiliationType;
                 author.Affiliation     = Affiliation;
                 author.OrcidId         = AuthorOrcidId;
                 author.IsPrimary       = IsPrimary;
                 author.EmployeeId      = AffiliateEmployeeId;
                 author.SetName(AuthorName, AffiliationType, AffiliateEmployeeId);
                 if (AffiliationType == AuthorAffilitionEnum.INL)
                 {
                     author.CountryId = null;
                     author.StateId   = null;
                 }
                 else
                 {
                     author.CountryId = CountryId;
                     if (CountryId.HasValue && CountryId.Value == Helper.UnitedStatesCountryId)
                     {
                         author.StateId = StateId;
                     }
                     else
                     {
                         author.StateId = null;
                     }
                 }
                 author.Save();
             }
         }
         else
         {
             AuthorObject.Add(AuthorId, MainId, AffiliateEmployeeId, AuthorName, AffiliationType, Affiliation, AuthorOrcidId, IsPrimary, CountryId, StateId);
         }
     }
 }