Exemple #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Category.Add(Category);
            await _context.SaveChangesAsync();

            int CategoryId = Category.CategoryId;

            parentParamterIds = Request.Form["AddParentParameters"];
            string[] parentParamterIdsArrayString = parentParamterIds.Split(",");
            int[]    parentParamterIdsArrayInt    = new int[parentParamterIdsArrayString.Length];
            for (int i = 0; i < parentParamterIdsArrayString.Length; i++)
            {
                parentParamterIdsArrayInt[i] = Convert.ToInt32(parentParamterIdsArrayString[i].ToString());
            }

            foreach (var ppId in parentParamterIdsArrayInt)
            {
                CategoryParentParameter = new Data.CategoryParentParameter()
                {
                    CategoryId        = CategoryId,
                    ParentParameterId = ppId
                };
                _context.CategoryParentParameter.Add(CategoryParentParameter);
                await _context.SaveChangesAsync();
            }
            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} created category {category} - carrying id {id} on {date}", user.Email, Category.CategoryName, Category.CategoryId, DateTime.Now);
            return(RedirectToPage("../Categories"));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync(List <string> ParameterName, List <string> ParameterDescription, List <string> ParameterUnit)
        {
            var user = await _userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                return(Page());
            }

            if (ParameterName.Count != ParameterDescription.Count || ParameterName.Count != ParameterUnit.Count)
            {
                InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                return(Page());
            }
            for (int i = 0; i < ParameterName.Count; i++)
            {
                if (ParameterName.ElementAt(i) == "" || ParameterDescription.ElementAt(i) == "" || ParameterUnit.ElementAt(i) == "")
                {
                    InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                    return(Page());
                }
                if (ParameterName.ElementAt(i) == null || ParameterDescription.ElementAt(i) == null || ParameterUnit.ElementAt(i) == null)
                {
                    InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                    return(Page());
                }
            }


            _context.ParentParameter.Add(ParentParameter);
            logger.Info("{user} added ParentParameter {ppName} carrying - id {id} on {date}", user.Email, ParentParameter.ParentParameterName, ParentParameter.ParentParameterId, DateTime.Now);
            await _context.SaveChangesAsync();


            if (ParameterName.Count != 0)
            {
                var ppId = ParentParameter.ParentParameterId;
                for (int i = 0; i < ParameterName.Count; i++)
                {
                    _context.Parameter.Add(
                        new Data.Parameter
                    {
                        ParameterDescription = ParameterDescription.ElementAt(i),
                        ParameterName        = ParameterName.ElementAt(i),
                        ParameterUnit        = ParameterUnit.ElementAt(i),
                        ParentParameterId    = ppId
                    }
                        );
                    logger.Info("{user} added Parameter {pName} under ParentParameter {ppname} carrying -id {id} on {date}", user.Email, ParameterName.ElementAt(i), ParentParameter.ParentParameterName, ppId, DateTime.Now);
                }

                await _context.SaveChangesAsync();
            }



            return(RedirectToPage("../Parameters"));
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                if (Review.ReviewContent != null)
                {
                    ViewData["ReviewContent"] = Review.ReviewContent;
                }
                ViewData["ArticleId"]   = _context.Article.FirstOrDefault(a => a.ArticleId == Review.ArticleId).ArticleId;
                ViewData["ArticleName"] = _context.Article.FirstOrDefault(a => a.ArticleId == Review.ArticleId).ArticleName;
                ViewData["UserId"]      = _userManager.GetUserId(User);
                return(Page());
            }

            string evalText = Request.Form["editContent"];

            Review.ReviewType = OnGetPredictSentiment(evalText);
            _context.Review.Add(Review);
            var user2 = await _userManager.GetUserAsync(User);

            logger.Info("{user} added a review for article carrying - id {id} on {date}", user2.Email, Review.ArticleId, DateTime.Now);
            await _context.SaveChangesAsync();

            return(RedirectToPage("/Article/Details", new { id = Review.ArticleId }));
        }
Exemple #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                CheckArticleContent();
                return(Page());
            }

            _context.Update(Article);
            _context.UpdateRange(ArticleParameters);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(Article.ArticleId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} edited article {article} - carrying {id} on {date}", user.Email, Article.ArticleName, Article.ArticleId, DateTime.Now);
            return(RedirectToPage("../Articles"));
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Category = await _context.Category.FindAsync(id);

            if (Category != null)
            {
                _context.Category.Remove(Category);
                await _context.SaveChangesAsync();
            }
            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} deteled category {category} - carrying {id} on {date}", user.Email, Category.CategoryName, Category.CategoryId, DateTime.Now);
            return(RedirectToPage("../Categories"));
        }
Exemple #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ParentParameter = await _context.ParentParameter.FindAsync(id);

            if (ParentParameter != null)
            {
                _context.ParentParameter.Remove(ParentParameter);
                await _context.SaveChangesAsync();
            }
            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} deleted ParentParameter {ppName} carrying - id {ppId} on {date}", user.Email, ParentParameter.ParentParameterName, ParentParameter.ParentParameterId, DateTime.Now);
            return(RedirectToPage("../Parameters"));
        }
Exemple #7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Article = await _context.Article.FindAsync(id);

            if (Article != null)
            {
                _context.Article.Remove(Article);
                await _context.SaveChangesAsync();
            }
            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} deleted article {article} - carrying {id} on {date}", user.Email, Article.ArticleName, Article.ArticleId, DateTime.Now);
            return(RedirectToPage("../Articles"));
        }
Exemple #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                if (Review.ReviewContent != null)
                {
                    ViewData["ReviewContent"] = Review.ReviewContent;
                }
                return(Page());
            }

            string evalText = Request.Form["editContent"];

            Review.ReviewType             = OnGetPredictSentiment(evalText);
            _context.Attach(Review).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                var user = await _userManager.GetUserAsync(User);

                logger.Info("{user} updated review on article carrying - id {id} on {date}", user.Email, Review.ArticleId, DateTime.Now);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(Review.UserId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Article/Details", new { id = Review.ArticleId }));
        }
Exemple #9
0
        public async Task <IActionResult> OnPostAsync(List <string> ParameterName, List <string> ParameterDescription, List <string> ParameterUnit, List <string> DelParams)
        {
            var user = await _userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (ParameterName.Count != ParameterDescription.Count || ParameterName.Count != ParameterUnit.Count)
            {
                InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                return(Page());
            }
            for (int i = 0; i < ParameterName.Count; i++)
            {
                if (ParameterName.ElementAt(i) == "" || ParameterDescription.ElementAt(i) == "" || ParameterUnit.ElementAt(i) == "")
                {
                    InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                    return(Page());
                }
                if (ParameterName.ElementAt(i) == null || ParameterDescription.ElementAt(i) == null || ParameterUnit.ElementAt(i) == null)
                {
                    InitParameter(ParameterName, ParameterDescription, ParameterUnit);
                    return(Page());
                }
            }

            _context.Update(ParentParameter);
            logger.Info("{user} updated ParentParameter {ppName} carrying -id {ppId} on {date}", user.Email, ParentParameter.ParentParameterName, ParentParameter.ParentParameterId, DateTime.Now);
            _context.UpdateRange(Parameters);

            try
            {
                await _context.SaveChangesAsync();

                if (DelParams.Count > 0)
                {
                    foreach (var item in DelParams)
                    {
                        if (item != null || item != "")
                        {
                            var temp = _context.Parameter.Where(p => p.ParameterId == Convert.ToInt32(item)).Single();
                            logger.Info("{user} edit-removed parameter {pName} carrying - id {pid} on {date}", user.Email, temp.ParameterName, temp.ParameterId, DateTime.Now);
                            _context.Parameter.Remove(temp);
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                if (ParameterName.Count != 0)
                {
                    var ppId = ParentParameter.ParentParameterId;
                    for (int i = 0; i < ParameterName.Count; i++)
                    {
                        _context.Parameter.Add(
                            new Data.Parameter
                        {
                            ParameterDescription = ParameterDescription.ElementAt(i),
                            ParameterName        = ParameterName.ElementAt(i),
                            ParameterUnit        = ParameterUnit.ElementAt(i),
                            ParentParameterId    = ppId
                        }
                            );
                        logger.Info("{user} edit-added Parameter {pName} under ParentParameter {ppname} carrying -id {id} on {date}", user.Email, ParameterName.ElementAt(i), ParentParameter.ParentParameterName, ppId, DateTime.Now);
                    }
                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ParentParameterExists(ParentParameter.ParentParameterId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("../Parameters"));
        }
Exemple #10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var ppRemoveIds = _context.CategoryParentParameter.Where(c => EF.Property <int>(c, "CategoryId") == Category.CategoryId);

            foreach (var ppRemoveIdsFE in ppRemoveIds)
            {
                _context.CategoryParentParameter.Remove(ppRemoveIdsFE);
            }

            _context.Attach(Category).State = EntityState.Modified;

            int CategoryId = Category.CategoryId;

            parentParamterIds = Request.Form["AddParentParameters"];

            if (parentParamterIds != null)
            {
                string[] parentParamterIdsArrayString = parentParamterIds.Split(",");
                int[]    parentParamterIdsArrayInt    = new int[parentParamterIdsArrayString.Length];
                for (int i = 0; i < parentParamterIdsArrayString.Length; i++)
                {
                    parentParamterIdsArrayInt[i] = Convert.ToInt32(parentParamterIdsArrayString[i].ToString());
                }

                foreach (var ppId in parentParamterIdsArrayInt)
                {
                    CategoryParentParameter = new Data.CategoryParentParameter()
                    {
                        CategoryId        = CategoryId,
                        ParentParameterId = ppId
                    };
                    _context.CategoryParentParameter.Add(CategoryParentParameter);
                    await _context.SaveChangesAsync();
                }
            }


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(Category.CategoryId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var user = await _userManager.GetUserAsync(User);

            logger.Info("{user} edited category {category} - carrying {id} on {date}", user.Email, Category.CategoryName, Category.CategoryId, DateTime.Now);
            return(RedirectToPage("../Categories"));
        }
Exemple #11
0
        public async Task <IActionResult> OnPostAsync(List <IFormFile> upFiles, ICollection <string> vals, ICollection <int> valIds)
        {
            if (upFiles == null || valIds == null || vals == null)
            {
                ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                parameters             = FindFirstParams();
                CheckArticleContent();
                ViewData["ImageCheck"] = false;
                return(Page());
            }
            else if (!ModelState.IsValid)
            {
                ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                CheckArticleContent();
                parameters = FindFirstParams();
                return(Page());
            }
            if (vals.Contains(null))
            {
                ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                CheckArticleContent();
                parameters           = FindFirstParams();
                ViewData["ValError"] = "Please fill all the parameter inputs";
                return(Page());
            }
            string[] captionList = ArticlePictures.ArticlePictureCaption.Split(";");
            if (upFiles.Count != captionList.Count())
            {
                ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                parameters             = FindFirstParams();
                CheckArticleContent();
                ViewData["CaptionError"] = "Please enter caption for each image seperated by `;`";
                return(Page());
            }
            foreach (var item in captionList)
            {
                if (item == null || item == "" || item == " ")
                {
                    ViewData["CategoryId"]   = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName");
                    ViewData["CaptionError"] = "Empty or Missing Caption Detected, Please enter caption for each image seperated by `;`";
                    CheckArticleContent();
                    parameters = FindFirstParams();
                    return(Page());
                }
            }
            _context.Article.Add(Article);
            await _context.SaveChangesAsync();

            var user2 = await _userManager.GetUserAsync(User);

            logger.Info("{user} created article {article} - carrying id {id} on {date}", user2.Email, Article.ArticleName, Article.ArticleId, DateTime.Now);

            var articleId = Article.ArticleId;
            var counter   = 0;

            foreach (var upFile in upFiles)
            {
                if (upFile != null || upFile.ContentType.ToLower().StartsWith("image/"))
                {
                    MemoryStream ms = new MemoryStream();
                    upFile.OpenReadStream().CopyTo(ms);

                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

                    Data.ArticlePicture upArticlePicture = new Data.ArticlePicture()
                    {
                        ArticleId             = articleId,
                        ArticlePictureCaption = captionList[counter++],
                        ArticlePictureBytes   = ms.ToArray()
                    };
                    _context.ArticlePicture.Add(upArticlePicture);
                }
            }
            await _context.SaveChangesAsync();

            for (int i = 0; i < vals.Count; i++)
            {
                Data.ArticleParameter articleParameter = new Data.ArticleParameter()
                {
                    ArticleId    = articleId,
                    ParameterId  = valIds.ElementAt(i),
                    ParameterVal = vals.ElementAt(i)
                };

                _context.ArticleParameter.Add(articleParameter);
            }
            await _context.SaveChangesAsync();

            return(RedirectToPage("../Articles"));
        }