Exemplo n.º 1
0
        public async Task <IActionResult> PutKnowledgeBaseEngineer(string id, KnowledgeBaseEngineer knowledgeBaseEngineer)
        {
            if (id != knowledgeBaseEngineer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(knowledgeBaseEngineer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KnowledgeBaseEngineerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,AuthorId")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Users, "Id", "Id", tag.AuthorId);
            return(View(tag));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,ActivityDate,Operation,Information,AuthorId")] Activity activity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(activity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Users, "Id", "Id", activity.AuthorId);
            return(View(activity));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,TagId,ArticleId,AuthorId")] ArticleTag articleTag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(articleTag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArticleId"] = new SelectList(_context.Articles, "Id", "SefName", articleTag.ArticleId);
            ViewData["AuthorId"]  = new SelectList(_context.Users, "Id", "Id", articleTag.AuthorId);
            ViewData["TagId"]     = new SelectList(_context.Tags, "Id", "Name", articleTag.TagId);
            return(View(articleTag));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var category = await _context.Categories.FindAsync(id);

            if (category == null)
            {
                return(NotFound());
            }
            try
            {
                //if (!_categoryRepository.HasArticleInCategory(id))
                if (!_categoryRepository.HasArticleInCategoryOrParentCategoryOrChildren(id))
                {
                    _context.Categories.Remove(category);
                    await _context.SaveChangesAsync();

                    //0109
                    _activityRepository.CategoryActivities(category, "deleted");

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    log.Info("Category Has Articles!");
                    //vrati se
                    return(BadRequest("Category Has Articles!"));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ModelState.AddModelError("Exception", ex.Message);
                return(View(category));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> DeleteConfirmed(long id)
        {
            var article = await _context.Articles.FindAsync(id);

            //*************************************************************
            //stari kod - vrati se

            while (article.Attachments.Count > 0)
            {
                var a = article.Attachments.First();
                attachmentHelper.RemoveLocalAttachmentFile(a);
                _lucene.RemoveAttachmentFromIndex(a);
                article.Attachments.Remove(a);

                /*
                 * Also remove the attachment from db.attachments collection
                 *
                 * http://stackoverflow.com/questions/17723626/entity-framework-remove-vs-deleteobject
                 *
                 * If the relationship is required (the FK doesn't allow NULL values) and the relationship is not
                 * identifying (which means that the foreign key is not part of the child's (composite) primary key)
                 * you have to either add the child to another parent or you have to explicitly delete the child
                 * (with DeleteObject then). If you don't do any of these a referential constraint is
                 * violated and EF will throw an exception when you call SaveChanges -
                 * the infamous "The relationship could not be changed because one or more of the foreign-key properties
                 * is non-nullable" exception or similar.
                 */
                _context.Attachments.Remove(a);
            }

            string currentUser = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            article.AuthorId = currentUser;
            //KbVaultLuceneHelper.RemoveArticleFromIndex(article);
            //*************************************************************



            _context.Articles.Remove(article);
            await _context.SaveChangesAsync();

            //0109 - activity
            _activityRepository.ArticleActivities(article, "deleted");


            return(RedirectToAction(nameof(Index)));
        }
        public async Task <JsonResult> UploadFiles()
        {
            string result = string.Empty, info = string.Empty;

            var  files    = Request.Form.Files;
            long filesize = files.Sum(f => f.Length);

            if (filesize > 1024 * 1024 * 6)
            {
                result = "Error";
                info   = "File size must be less than 6 MB.";
            }
            else
            {
                if (files.Count > 0 && filesize > 0)
                {
                    foreach (var f in files)
                    {
                        string fileExtend   = new FileInfo(f.FileName).Extension;
                        string filepureName = f.FileName.Substring(f.FileName.LastIndexOf("\\") + 1);
                        if (fileExtend == ".pdf")
                        {
                            var filePath = _hostingEnvironment.WebRootPath + @"\assets\upload\ebooks\" + filepureName;

                            var checkMod = _context.EBook.Where(m => m.BookName == filepureName).ToList();
                            if (checkMod != null && checkMod.Count > 0)
                            {
                                result = "Error";
                                info   = "This book already exist.";
                            }
                            else
                            {
                                if (f.Length > 0)
                                {
                                    using (var stream = new FileStream(filePath, FileMode.Create))
                                    {
                                        await f.CopyToAsync(stream);
                                    }

                                    try
                                    {
                                        EBook eBook = new EBook()
                                        {
                                            Author         = HttpContext.Request.Cookies["displayname"],
                                            BookName       = filepureName,
                                            Classification = Request.Form["classification"].ToString(),
                                            Datetime       = DateTime.Now,
                                            Path           = @"\assets\upload\ebooks\" + filepureName
                                        };
                                        _context.EBook.Add(eBook);
                                        await _context.SaveChangesAsync();
                                    }
                                    catch (Exception e)
                                    {
                                        result = "Error"; info = e.Message;
                                    }
                                }
                            }
                        }
                        else
                        {
                            result = "Error"; info = "Just allow upload PDF file.";
                        }
                    }
                    if (string.IsNullOrEmpty(result))
                    {
                        result = "Ok";
                        info   = "Update Successful.";
                    }
                }
                else
                {
                    result = "Error";
                    info   = "Please choose upload file!";
                }
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("result", result);
            dic.Add("info", info);

            return(Json(dic));
        }