Exemple #1
0
        // GET: Projects
        public async Task <IActionResult> Index(string searchString, string categoryString)
        {
            var projects = from p in _context.Project select p;

            List <string> categoryQuery = new List <string>()
            {
                "1",
                "2"
            };


            if (!String.IsNullOrEmpty(searchString))
            {
                projects = projects.Where(p => p.Name.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(categoryString))
            {
                if (int.TryParse(categoryString, out int cat))
                {
                    projects = projects.Where(p => p.Category == cat);
                }
            }

            var projectsCategoryViewModel = new ProjectCategoryViewModel()
            {
                Categories = new SelectList(categoryQuery),
                Projects   = await projects.ToListAsync()
            };

            return(View(projectsCategoryViewModel));
        }
Exemple #2
0
        public async Task UpdateAsync(ProjectCategoryViewModel projectCategoryVM)
        {
            ProjectCategory projectCategory = _mapper.Map <ProjectCategory>(projectCategoryVM);

            _dataContext.ProjectCategories.Update(projectCategory);
            await _dataContext.SaveChangesAsync();
        }
Exemple #3
0
        public ActionResult Create()
        {
            var model = new ProjectCategoryViewModel();

            //locales
            AddLocales(_languageService, model.Locales);

            //default values
            model.CreatedOnUtc = DateTime.UtcNow;

            return(View("~/Plugins/Cameleo.CameleoEvents/Views/Admin/Project/Create.cshtml", model));
        }
Exemple #4
0
        /// <summary>
        /// Get ProjectCategoryViewModel
        /// </summary>
        public ProjectCategoryViewModel GetProjectCategoryViewModel(int projectCategoryId)
        {
            var tmpCategory = GetProjectCategoryById(projectCategoryId);

            if (tmpCategory == null)
            {
                return(null);
            }
            else
            {
                ProjectCategoryViewModel projectCategoryViewModel = new ProjectCategoryViewModel(tmpCategory);
                return(projectCategoryViewModel);
            }
        }
Exemple #5
0
        protected virtual void UpdateLocales(CameleoProjectCategory projectCategory, ProjectCategoryViewModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(projectCategory,
                                                           x => x.Name,
                                                           localized.Name,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(projectCategory,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);
            }
        }
Exemple #6
0
        public async Task <ProjectCategoryViewModel> GetByIdAsync(string id)
        {
            ProjectCategoryViewModel result = await(from pc in _dataContext.ProjectCategories
                                                    where pc.Id == id
                                                    select new ProjectCategoryViewModel
            {
                Id          = pc.Id,
                Position    = pc.Position,
                Name_VN     = pc.Name_VN,
                Name_EN     = pc.Name_EN,
                CreatedBy   = pc.CreatedBy,
                CreatedDate = pc.CreatedDate,
                Status      = pc.Status
            }).FirstOrDefaultAsync();

            return(result);
        }
        public IActionResult SaveEntity(ProjectCategoryViewModel projectCategoryVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }

            if (projectCategoryVm.Id == 0)
            {
                _projectCategoryService.Add(projectCategoryVm);
            }
            else
            {
                _projectCategoryService.Update(projectCategoryVm);
            }

            _projectCategoryService.Save();
            return(new OkObjectResult(projectCategoryVm));
        }
Exemple #8
0
        public ActionResult Create(ProjectCategoryViewModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var projectCategory = new CameleoProjectCategory();
                projectCategory.Name         = model.Name;
                projectCategory.Description  = model.Description;
                projectCategory.CreatedOnUtc = model.CreatedOnUtc;
                _projectCategoryService.InsertProjectCategory(projectCategory);

                //locales
                UpdateLocales(projectCategory, model);

                SuccessNotification(_localizationService.GetResource("Plugins.Cameleo.ProjectCategories.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = projectCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/Admin/Project/Create.cshtml", model));
        }
Exemple #9
0
        public ActionResult Edit(ProjectCategoryViewModel model, bool continueEditing)
        {
            //Get Category
            var category = _projectCategoryService.GetProjectCategoryById(model.Id);

            if (category == null)
            {
                //No category found with the specified id
                return(RedirectToAction("List"));
            }

            //Valid model?
            if (ModelState.IsValid)
            {
                //Yes

                //Update
                category.Name        = model.Name;
                category.Description = model.Description;
                _projectCategoryService.UpdateProjectCategory(category);

                //locales
                UpdateLocales(category, model);
                SuccessNotification(_localizationService.GetResource("Plugins.Cameleo.ProjectCategories.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", new { id = category.Id }));
                }
                else
                {
                    return(RedirectToAction("List"));
                }
            }

            //If we got this far, something failed, redisplay form
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/Admin/Project/Edit.cshtml", model));
        }
Exemple #10
0
        /// <summary>
        /// Get ProjectCategoryListViewModel for all Project categories
        /// </summary>
        public ProjectCategoryListViewModel GetProjectCategoryListViewModel()
        {
            var records = GetAllProjectCategories();
            var projectCategoriesModel = records
                                         .Select(x =>
            {
                var m = new ProjectCategoryViewModel()
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    Description  = x.Description,
                    CreatedOnUtc = x.CreatedOnUtc,
                };
                return(m);
            })
                                         .ToList();
            var model = new ProjectCategoryListViewModel();

            model.ProjectCategoryList = projectCategoriesModel;

            return(model);
        }
Exemple #11
0
        public async Task <ProjectCategoryViewModel> CreateAsync(ProjectCategoryViewModel projectCategoryVM)
        {
            ProjectCategory projectCategory = _mapper.Map <ProjectCategory>(projectCategoryVM);

            if (_dataContext.ProjectCategories.Any())
            {
                int?maxPosition = await _dataContext.ProjectCategories.MaxAsync(x => x.Position);

                projectCategory.Position = maxPosition + 1;
            }
            else
            {
                projectCategory.Position = 1;
            }

            await _dataContext.ProjectCategories.AddAsync(projectCategory);

            await _dataContext.SaveChangesAsync();

            ProjectCategoryViewModel result = _mapper.Map <ProjectCategoryViewModel>(projectCategory);

            return(result);
        }
Exemple #12
0
 public async Task DeleteAsync(ProjectCategoryViewModel projectCategoryVM)
 {
     await DeleteAsync(projectCategoryVM.Id);
 }
        public void Update(ProjectCategoryViewModel projectCategoryVm)
        {
            var projectCategory = Mapper.Map <ProjectCategoryViewModel, ProjectCategory>(projectCategoryVm);

            _projectCategoryRepository.Update(projectCategory);
        }