public ActionResult <ActivityAddResViewModel> Manage_OpinionInfo_Add(ActivityAddViewModel activityAddViewModel)
        {
            activityAddViewModel.Id = Guid.NewGuid();
            int Activity_add_Count;

            Activity_add_Count = _activityService.AddActivity(activityAddViewModel);
            var opinionInfoAddResModel = _activityFactory.GetActivityAddResViewModel();

            //添加附件中的FormId
            foreach (FileUpload fileUpload in activityAddViewModel.Files)
            {
                fileUpload.FormId = activityAddViewModel.Id;
                _activityUploadService.UpdateFile(fileUpload);
            }

            if (Activity_add_Count > 0)
            {
                opinionInfoAddResModel.baseViewModel.IsSuccess = true;
                opinionInfoAddResModel.AddCount = Activity_add_Count;
                opinionInfoAddResModel.baseViewModel.Message      = "添加成功";
                opinionInfoAddResModel.baseViewModel.ResponseCode = 200;
                _ILogger.Information("增添活动信息成功");
                return(Ok(opinionInfoAddResModel));
            }
            else
            {
                opinionInfoAddResModel.baseViewModel.IsSuccess = false;
                opinionInfoAddResModel.AddCount = 0;
                opinionInfoAddResModel.baseViewModel.Message      = "添加失败";
                opinionInfoAddResModel.baseViewModel.ResponseCode = 400;
                _ILogger.Information("增添活动信息失败");
                return(BadRequest(opinionInfoAddResModel));
            }
        }
Пример #2
0
        // GET: Activity/Create
        public async Task <IActionResult> Create(int id)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }
            var module = await _context.Modules.Include(m => m.Course).FirstOrDefaultAsync(m => m.Id == id);

            if (module is null)
            {
                return(NotFound());
            }

            var model = new ActivityAddViewModel();

            model.ModuleId   = module.Id;
            model.ModuleName = module.Name;
            model.Module     = module;
            model.Course     = module.Course;

            model.ParentStartDate = module.StartDate;
            model.ParentEndDate   = module.EndDate;
            model.ModuleName      = module.Name;

            var startTimeActivity = module.StartDate;

            model.StartDate = startTimeActivity;

            model.EndDate = startTimeActivity.AddDays(7);

            ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Type");

            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="activityAddViewModel"></param>
        /// <returns></returns>
        public int AddActivity(ActivityAddViewModel activityAddViewModel)
        {
            var aAddInsertModel = _IMapper.Map <ActivityAddViewModel, Activity>(activityAddViewModel);

            //var a = new InfoRelationShip();
            _activityRepository.Add(aAddInsertModel);
            return(_activityRepository.SaveChanges());
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id, Description, StartDate, EndDate, ModuleId, ModuleName, ActivityTypeId, ParentStartDate, ParentEndDate")] ActivityAddViewModel AVM)
        {
            if (ModelState.IsValid)
            {
                var ActivityEntity = await _context.Activities.Include(a => a.ActivityType).FirstOrDefaultAsync(a => a.Id == AVM.Id);

                ActivityEntity.Description = AVM.Description;
                ActivityEntity.StartDate   = AVM.StartDate;
                ActivityEntity.EndDate     = AVM.EndDate;
                //ActivityEntity.ModuleId = AVM.ModuleId;
                ActivityEntity.ActivityTypeId = AVM.ActivityTypeId;
                _context.Update(ActivityEntity);
                await _context.SaveChangesAsync();

                TempData["AlertMsg"] = "Saved changes";
                return(RedirectToAction(nameof(Details), new { id = id }));
            }

            var activity = await _context.Activities
                           .Include(a => a.Module)
                           .FirstOrDefaultAsync(a => a.Id == id);

            if (activity == null || activity.Module is null)
            {
                return(NotFound());
            }

            var course = await _context.Courses.FirstOrDefaultAsync(a => a.Id == activity.Module.CourseId);

            if (course == null)
            {
                return(NotFound());
            }

            AVM.Course     = course;
            AVM.Module     = activity.Module;
            AVM.ModuleId   = activity.Module.Id;
            AVM.ModuleName = activity.Module.Name;

            ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Type", AVM.ActivityTypeId);
            return(View(AVM));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("Description, StartDate, EndDate, ModuleId, ModuleName, ActivityTypeId, ParentStartDate, ParentEndDate")] ActivityAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Activityy activity = _mapper.Map <Activityy>(viewModel);
                activity.ActivityType = await _context.ActivityType.FirstOrDefaultAsync(at => at.Id == viewModel.ActivityTypeId);

                activity.Module = await _context.Modules.FirstOrDefaultAsync(m => m.Id == viewModel.ModuleId);

                await _context.Activities.AddAsync(activity);

                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                TempData["AlertMsg"] = "Activity added";
                return(RedirectToAction("Details", "module", new { id = activity.Module.Id }));
            }


            var module = await _context.Modules.Include(m => m.Course).FirstOrDefaultAsync(m => m.Id == viewModel.ModuleId);

            if (module is null)
            {
                return(NotFound());
            }

            var course = await _context.Courses.FirstOrDefaultAsync(a => a.Id == module.CourseId);

            if (course == null)
            {
                return(NotFound());
            }

            viewModel.Course     = course;
            viewModel.Module     = module;
            viewModel.ModuleId   = module.Id;
            viewModel.ModuleName = module.Name;

            ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Type");
            return(View(viewModel));
        }