예제 #1
0
        public ActionResult GetAuthor(Guid?Id, PageMode status)
        {
            try
            {
                if (Session["ArticleAuthors"] == null)
                {
                    Session["ArticleAuthors"] = new List <ArticleAuthors>();
                }
                ArticleAuthors articleAuthors = null;
                switch (status)
                {
                case PageMode.Create:
                    articleAuthors = new ArticleAuthors()
                    {
                        Id = Guid.NewGuid()
                    };
                    break;

                case PageMode.Edit:
                    var list = (List <ArticleAuthors>)Session["ArticleAuthors"];
                    articleAuthors = list.FirstOrDefault(organization => organization.Id.Equals(Id));
                    break;
                }
                this.PrepareViewBags(articleAuthors, status);
                return(PartialView("PartialViewArticleAuthor", articleAuthors));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #2
0
        public ActionResult GetAuthor(FormCollection collection)
        {
            try
            {
                ArticleAuthors articleAuthors = null;
                PageMode       pageMode       = base.GetPageMode <ArticleAuthors>(collection);
                var            id             = base.GetModelKey <ArticleAuthors>(collection);
                var            list           = (List <ArticleAuthors>)Session["ArticleAuthors"];
                var            guid           = id[0].ToString().ToGuid();
                if (string.IsNullOrEmpty(collection["Name"]))
                {
                    ShowMessage(Resources.Congress.PleaseEnterAuthorName, Resources.Common.MessaageTitle,
                                messageIcon: MessageIcon.Warning);
                    return(Content("false"));
                }
                else
                {
                    if (list.Any(x => x.Name == collection["Name"] && x.Id != guid))
                    {
                        ShowMessage($"نویسنده {collection["Name"]} قبلا ثبت شده است", Resources.Common.MessaageTitle,
                                    messageIcon: MessageIcon.Warning);
                        return(Content("false"));
                    }
                }
                if (!string.IsNullOrEmpty(collection["Percentage"]))
                {
                    if (collection["Percentage"].ToByte() <= 0)
                    {
                        ShowMessage(Resources.Congress.PleaseEnterTheAuthorContributionPercentage, Resources.Common.MessaageTitle,
                                    messageIcon: MessageIcon.Warning);
                        return(Content("false"));
                    }
                    var sumPercent = list.Sum(x => x.Percentage);
                    if (sumPercent + collection["Percentage"].ToByte() > 100)
                    {
                        ShowMessage(Resources.Congress.TotalPercentage, Resources.Common.MessaageTitle,
                                    messageIcon: MessageIcon.Warning);
                        return(Content("false"));
                    }
                }

                switch (pageMode)
                {
                case PageMode.Edit:
                    articleAuthors = list.FirstOrDefault(organizationIp => organizationIp.Id.Equals(guid));
                    if (articleAuthors == null)
                    {
                        return(Content("false"));
                    }
                    RadynTryUpdateModel(articleAuthors, collection);
                    if (articleAuthors.IsDirector)
                    {
                        if (!list.Any(x => x.IsDirector & x.Id != articleAuthors.Id))
                        {
                            return(Content("true"));
                        }
                        ShowMessage(string.Format(Resources.Congress.AuthorDirectorAddedThisArticle, this.Homa.Configuration.ArticleTitle), Resources.Common.MessaageTitle,
                                    messageIcon: MessageIcon.Error);
                        return(Content("false"));
                    }
                    return(Content("true"));

                case PageMode.Create:
                    articleAuthors = new ArticleAuthors();
                    RadynTryUpdateModel(articleAuthors, collection);
                    if (articleAuthors.IsDirector)
                    {
                        if (list.Any(x => x.IsDirector))
                        {
                            ShowMessage(string.Format(Resources.Congress.AuthorDirectorAddedThisArticle, this.Homa.Configuration.ArticleTitle), Resources.Common.MessaageTitle,
                                        messageIcon: MessageIcon.Error);
                            return(Content("false"));
                        }
                    }
                    articleAuthors.Order = list.Count == 0 ? 1 : list.Max(x => x.Order) + 1;
                    list.Add(articleAuthors);
                    return(Content("true"));
                }
                ShowMessage(Resources.Common.ErrorInInsert, Resources.Common.MessaageTitle, messageIcon: MessageIcon.Error);
                return(Content("false"));
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex);
                return(Content("false"));
            }
        }
        public async Task <IActionResult> FetchArticles()
        {
            using (var db = new CrossRefContext())
            {
                var user = db.Users.First(u => u.Email.Equals(
                                              User.FindFirst(ClaimTypes.Email).Value));

                var articles = await CrossRefService.FetchArticles(
                    user.FirstName + " " + user.LastName,
                    user.Affiliation);

                foreach (var article in articles)
                {
                    var existingArticle = db.Articles
                                          .Include("ArticleAuthors")
                                          .FirstOrDefault(a => a.DOI.Equals(article.DOI));

                    if (existingArticle != null)
                    {
                        if (existingArticle.ArticleAuthors.Any(aa => aa.UserId == user.Id))
                        {
                            continue;
                        }

                        var manyToManyBullshit = existingArticle.ArticleAuthors;
                        manyToManyBullshit.Add(new ArticleAuthors
                        {
                            User    = user,
                            Article = existingArticle
                        });

                        existingArticle.ArticleAuthors = manyToManyBullshit;
                        db.Articles.Update(existingArticle);
                        db.SaveChanges();
                    }
                    else
                    {
                        var newArticle = new Article
                        {
                            DOI               = article.DOI,
                            Title             = article.Title,
                            YearOfPublication = article.YearOfPublication
                        };

                        var aa = new ArticleAuthors
                        {
                            Article = newArticle,
                            User    = user
                        };
                        newArticle.ArticleAuthors = new List <ArticleAuthors> {
                            aa
                        };

                        db.Articles.Add(newArticle);
                        db.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("MyOverview", "Profile"));
        }