Esempio n. 1
0
        public IActionResult AddCompetition()
        {
            var CurrentUserId = _userManager.GetUserId(User as ClaimsPrincipal);
            ArtGalleryContext       context = new ArtGalleryContext();
            AddCompetitionViewModel comvm   = new AddCompetitionViewModel();

            comvm.CategoryList    = context.Category.ToList();
            comvm.SubCategoryList = context.SubCategory.ToList();
            comvm.FullName        = context.Account.Where(A => A.Id == CurrentUserId).Select(A => A.FirstName).FirstOrDefault();
            comvm.ProfilePicture  = context.ProfileImage.Where(PI => PI.AccountId == CurrentUserId).Select(PI => PI.ImageName).FirstOrDefault();
            return(View(comvm));
        }
Esempio n. 2
0
        public ActionResult Add(AddCompetitionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var comp = new Competitions()
                {
                    Name   = model.name,
                    Status = Status.Active
                };

                unitOfWork.CompetitionRepository.Insert(comp);
                unitOfWork.Save();
                Log(JsonConvert.SerializeObject(model), LogEvent.CompetitionAdd.ToString(), comp.ID, "competition");
                AddApplicationMessage("Soutěž byla úspešně založena", MessageSeverity.Success);

                return(RedirectToAction("Admin", "Competitions"));
            }
            AddApplicationMessage("Nepodařilo se založit soutěž, zkontrolujte formulář", MessageSeverity.Danger);
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Edit(AddCompetitionViewModel model)
        {
            if (ModelState.IsValid && model.compid != null)
            {
                var comp = unitOfWork.CompetitionRepository.GetByID(model.compid);
                if (comp != null)
                {
                    comp.Name = model.name;

                    unitOfWork.CompetitionRepository.Update(comp);
                    unitOfWork.Save();
                    Log(JsonConvert.SerializeObject(model), LogEvent.CompetitionEdit.ToString(), comp.ID, "competition");
                    AddApplicationMessage("Soutěž byla úspešně změněna", MessageSeverity.Success);

                    return(RedirectToAction("Admin", "Competitions"));
                }
            }
            AddApplicationMessage("Nepodařilo se uložit soutěž, zkontrolujte formulář", MessageSeverity.Danger);
            return(View(model));
        }
Esempio n. 4
0
        public ActionResult Edit(int?compid)
        {
            if (compid == null)
            {
                AddApplicationMessage("Nebyl uveden identifikátor soutěže", MessageSeverity.Danger);
                return(RedirectToAction("Admin", "Competitions"));
            }

            Competitions comp = unitOfWork.CompetitionRepository.GetByID(compid);

            if (comp == null)
            {
                AddApplicationMessage("Id neodpovídá žádné soutěži", MessageSeverity.Danger);
                return(RedirectToAction("Admin", "Competitions"));
            }

            var model = new AddCompetitionViewModel()
            {
                compid = compid,
                name   = comp.Name
            };

            return(View(model));
        }
Esempio n. 5
0
        public async Task <IActionResult> UpdateCompetition(UpdateCompetitionViewModel updateCompetition)
        {
            ////EF core start

            ArtGalleryContext       GetCompetition = new ArtGalleryContext();
            AddCompetitionViewModel AVM            = new AddCompetitionViewModel();


            var TargetCompetition = GetCompetition.Competition.FirstOrDefault(O => O.CompetitionId == updateCompetition.UpdatedPost.CompetitionId);       //Find the psot

            //var PostTag = GetCompetition.PostTag.Include(a => a.Tag).FirstOrDefault(O => O.PostId == updatePost.Post.PostId);      //Find the first PostTag for the target Psot
            //var PostTags = GetCompetition.PostTag.Where(A => A.PostId == updatePost.Post.PostId).Include(A => A.Tag).ToList();    //Get list of PostTag for the target Psot

            //var CompetitionImage = GetCompetition.Image.Where(I => I.CompetitionId == updateCompetition.UpdatedPost.CompetitionId).Where(I => I.IsPrimary == true).FirstOrDefault();

            //Post.Body = Post.Body;
            TargetCompetition.Title   = updateCompetition.UpdatedPost.CompetitionTitle;    //Replace edited title to target
            TargetCompetition.Caption = updateCompetition.UpdatedPost.CompetitionCaption;  //Replace edited Caption to target
            //TargetCompetition.Category.Name = updateCompetition.UpdatedPost.Category;     //Replace edited Category to target
            //TargetCompetition.SubCategory.Name = updateCompetition.UpdatedPost.SubCategory;      //Replace edited title to target


            GetCompetition.Competition.Update(TargetCompetition);
            GetCompetition.SaveChanges();

            #region EditPosteImage

            if (updateCompetition.UpdatedPost.CompetitionImage != null)
            {
                var uploadsRootFolder = Path.Combine(_environment.WebRootPath, "img/Competition");

                string path = Path.Combine(uploadsRootFolder, /*CompetitionImage.Name*/ "");
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                //GetCompetition.Image.Remove(CompetitionImage);
                GetCompetition.SaveChanges();

                if (!Directory.Exists(uploadsRootFolder))
                {
                    Directory.CreateDirectory(uploadsRootFolder);
                }


                if (updateCompetition.UpdatedPost.CompetitionImage == null || updateCompetition.UpdatedPost.CompetitionImage.Length == 0)
                {
                    await Response.WriteAsync("Error");
                }

                var filePath = Path.Combine(uploadsRootFolder, updateCompetition.UpdatedPost.CompetitionImage.FileName);

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await updateCompetition.UpdatedPost.CompetitionImage.CopyToAsync(fileStream).ConfigureAwait(false);
                }

                Guid guidImage = new Guid();
                ArtGalleryContext CompetitionImageContext = new ArtGalleryContext();
                Image             ImageCompetition        = new Image();
                ImageCompetition.Name      = updateCompetition.UpdatedPost.CompetitionImage.FileName;
                ImageCompetition.ImageName = guidImage + updateCompetition.UpdatedPost.CompetitionImage.FileName;
                ImageCompetition.PostId    = updateCompetition.UpdatedPost.CompetitionId;
                ImageCompetition.IsPrimary = true;
                CompetitionImageContext.Image.Add(ImageCompetition);
                CompetitionImageContext.SaveChanges();
            }

            #endregion

            #region EditTags
            //foreach (var AT in PostTags)
            //{
            //    bool exist = false;
            //    foreach (var inputtag in updatePost.Tags)
            //    {

            //        if (inputtag == AT.Tag.Name)
            //        {
            //            exist = true;
            //        }

            //    }
            //    if (exist == false)
            //    {
            //        GetPost.PostTag.Remove(AT);
            //        await GetPost.SaveChangesAsync();
            //    }
            //}
            #endregion

            ////EF core end
            return(new RedirectResult("Competition"));
        }
Esempio n. 6
0
        public async Task <IActionResult> AddCompetition(AddCompetitionViewModel AddCompetition)
        {
            if (!ModelState.IsValid)
            {
                return(View(AddCompetition));
            }
            else if (ModelState.IsValid)
            {
                ArtGalleryContext CompetitionContext = new ArtGalleryContext();

                Competition competition = new Competition();

                var catId    = CompetitionContext.Category.Where(C => C.Name == AddCompetition.Category).Select(C => C.CategoryId).FirstOrDefault();
                var subcatId = CompetitionContext.SubCategory.Where(C => C.Name == AddCompetition.SubCategory).Select(C => C.SubCategoryId).FirstOrDefault();

                competition.Title         = AddCompetition.CompetitionTitle;   //Replace Add title to target
                competition.Caption       = AddCompetition.CompetitionCaption; //Replace Add Caption to target
                competition.StartDate     = DateTime.Now;                      //Replace Add Caption to target
                competition.CategoryId    = catId;                             //Replace Add Category to target
                competition.SubCategoryId = subcatId;                          //Replace Add title to target

                CompetitionContext.Competition.Add(competition);
                CompetitionContext.SaveChanges();

                //  Add Competition image started
                #region PostImage

                Guid guidImage = Guid.NewGuid();

                var uploadsRootFolder = Path.Combine(_environment.WebRootPath, "img/Competition");
                if (!Directory.Exists(uploadsRootFolder))
                {
                    Directory.CreateDirectory(uploadsRootFolder);
                }


                if (AddCompetition.CompetitionImage == null || AddCompetition.CompetitionImage.Length == 0)
                {
                    await Response.WriteAsync("Error");
                }

                var filePath = Path.Combine(uploadsRootFolder, guidImage + AddCompetition.CompetitionImage.FileName);

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await AddCompetition.CompetitionImage.CopyToAsync(fileStream).ConfigureAwait(false);
                }

                ArtGalleryContext CompetitionImageContext = new ArtGalleryContext();
                Image             ImageCompetition        = new Image();
                ImageCompetition.Name         = AddCompetition.CompetitionImage.FileName;
                ImageCompetition.ImageName    = guidImage + AddCompetition.CompetitionImage.FileName;
                ImageCompetition.ImageAddress = filePath;
                //ImageCompetition.CompetitionId = competition.CompetitionId;
                ImageCompetition.PostId    = 1;
                ImageCompetition.IsPrimary = true;
                CompetitionImageContext.Image.Add(ImageCompetition);
                CompetitionImageContext.SaveChanges();

                #endregion
                //  Add Competition image ended

                // Tags strated
                #region Tags
                //ArtGalleryContext GetTag = new ArtGalleryContext();
                //ArtGalleryContext TagInsertion = new ArtGalleryContext();
                //foreach (var newtag in AddCompetition.Tags)
                //{
                //    if (newtag != null)
                //    {
                //        var CheckTag = GetTag.Tag.FirstOrDefault(T => T.Name == newtag);
                //        Tag InsertionObj = new Tag();
                //        if (CheckTag == null)
                //        {
                //            InsertionObj.Name = newtag;
                //            TagInsertion.Tag.Add(InsertionObj);
                //            TagInsertion.SaveChanges();
                //            TagInsertion.PostTag.Add(new PostTag { PostId = post.PostId, TagId = InsertionObj.TagId });
                //            TagInsertion.SaveChanges();
                //        }
                //        else
                //        {
                //            TagInsertion.PostTag.Add(new PostTag { PostId = post.PostId, TagId = CheckTag.TagId });
                //            TagInsertion.SaveChanges();
                //        }
                //    }
                //}

                #endregion
                // Tags ended

                return(RedirectToAction("AddCompetition"));
            }
            else
            {
                return(View());
            }
        }