public async Task <MainResponse> AddClassResult(AddClassResultRequest addClassResultRequest, string actionBy)
        {
            var resultCheck = _resultRepository.GetSingle(x => x.ClassId == addClassResultRequest.ClassId && x.ExhibitorId == addClassResultRequest.ExhibitorId &&
                                                          x.IsActive == true && x.IsDeleted == false);

            if (resultCheck != null)
            {
                _mainResponse.Message = Constants.RECORD_AlREADY_EXIST;
                _mainResponse.Success = false;
                return(_mainResponse);
            }
            var ageGroup = _classRepository.GetSingle(x => x.ClassId == addClassResultRequest.ClassId);

            var addResult = new Result
            {
                ClassId     = addClassResultRequest.ClassId,
                AgeGroup    = ageGroup.AgeGroup,
                ExhibitorId = addClassResultRequest.ExhibitorId,
                Placement   = addClassResultRequest.Place,
                IsActive    = true,
                CreatedBy   = actionBy,
                CreatedDate = DateTime.Now
            };

            await _resultRepository.AddAsync(addResult);

            _mainResponse.Message = Constants.CLASS_RESULT_ADDED;
            _mainResponse.Success = true;
            return(_mainResponse);
        }
        public async Task <IActionResult> Add(ResultModel model, [FromServices] IHostingEnvironment env)
        {
            //判断传过来的数据是否合法
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string filename = string.Empty;

            if (model.Attachment != null)
            {
                //拼接起来
                filename = Path.Combine("file", Guid.NewGuid().ToString() + Path.GetExtension(model.Attachment.FileName));
                //var stream = new FileStream(Path.Combine(env.WebRootPath,filename), FileMode.CreateNew);
                using (var stream = new FileStream(Path.Combine(env.WebRootPath, filename), FileMode.CreateNew))
                {
                    model.Attachment.CopyTo(stream);
                }
            }
            await ResultRepository.AddAsync(new Result
            {
                strName     = model.strName,
                Title       = model.Title,
                Create      = DateTime.Now,
                Discription = model.Discription,
                TypeId      = model.TypeId,
                Password    = model.Password,
                Attachment  = filename
            });

            return(RedirectToAction("index"));
        }
Exemple #3
0
        //异步方法                           特性:来自于服务注册,获取环境变量
        public async Task <IActionResult> Add([FromServices] IHostingEnvironment env, ResultModel model)
        {
            //判断是否合理
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //上传路径
            string filename = string.Empty;

            if (model.Attachmet != null)
            {
                //文件夹   字符串                   上传文件的扩展名
                filename = Path.Combine("file", Guid.NewGuid().ToString() + Path.GetExtension(model.Attachmet.FileName));
                //using为了及时关闭文件流  //绝对路径
                using (var stream = new FileStream(Path.Combine(env.WebRootPath, filename), FileMode.CreateNew)) {
                    model.Attachmet.CopyTo(stream);//文件直接复制到wwwroot中的file文件夹中
                }
                // env.WebRootPath + filename
            }

            await _resultRepository.AddAsync(new Models.Result
            {
                SName       = model.SName,
                Title       = model.Title,
                Discription = model.Discription,
                Create      = DateTime.Now,
                TID         = model.TID,
                PassWord    = model.PassWord,
                Attachmet   = filename
            });

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Post([FromBody] ResultModel model)
        {
            await _resultRepository.AddAsync(new Models.Result
            {
                SName       = model.SName,
                Title       = model.Title,
                Discription = model.Discription,
                Create      = DateTime.Now,
                TID         = model.TID
            });

            return(Content("ok"));
        }
Exemple #5
0
        public async Task <SaveResultResponse> SaveAsync(Result result)
        {
            try
            {
                await _resultRepository.AddAsync(result);

                await _unitOfWork.CompleteAsync();

                return(new SaveResultResponse(result));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveResultResponse($"An error occurred when saving the category: {ex.Message}"));
            }
        }
        public async Task <IActionResult> Add(ResultModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await resultRepository.AddAsync(new Models.Result
            {
                StuName     = model.StuName,
                Title       = model.Title,
                Description = model.Description,
                Create      = DateTime.Now,
                TypeId      = model.TypeId
            });;

            return(RedirectToAction("Index"));
        }
        public async Task <MainResponse> AddClassResult(AddClassResultRequest addClassResultRequest, string actionBy)
        {
            var ageGroup = _classRepository.GetSingle(x => x.ClassId == addClassResultRequest.ClassId);

            var addResult = new Result
            {
                ClassId     = addClassResultRequest.ClassId,
                AgeGroup    = ageGroup.AgeGroup,
                ExhibitorId = addClassResultRequest.ExhibitorId,
                HorseId     = addClassResultRequest.HorseId,
                Placement   = addClassResultRequest.Place,
                IsActive    = true,
                CreatedBy   = actionBy,
                CreatedDate = DateTime.Now
            };

            await _resultRepository.AddAsync(addResult);

            _mainResponse.Message = Constants.CLASS_RESULT_ADDED;
            _mainResponse.Success = true;
            return(_mainResponse);
        }
Exemple #8
0
        public async Task AddAsync(CreateResultViewModel model)
        {
            var u = await _adminService.GetUserByIdAsync(model.UserId);

            var c = _adminService.GetCountryNameById(u.Country);
            var n = _adminService.GetNationalityById(u.Nationality);
            var r = new Result
            {
                UserId      = model.UserId,
                HeatId      = model.HeatId,
                Club        = null, //TODO
                Country     = c,
                Created     = DateTime.Now,
                FinalTime   = null,
                Gender      = u.Gender,
                Modified    = DateTime.Now,
                Name        = u.FirstName + " " + u.LastName,
                Nationality = n,
                Notes       = null,
                Status      = 0
            };
            await _repo.AddAsync(r);
        }