コード例 #1
0
        public async override Task UpdateAsync(object request)
        {
            if (!(request is UpdateSchoolYearRequest))
            {
                throw new Exception("Convert type not allowed");
            }

            UpdateSchoolYearRequest req = (UpdateSchoolYearRequest)request;
            SchoolYear item             = await _repository.GetByIdAsync(req.Id);

            if (item == null)
            {
                throw new Exception("SchoolYear not found");
            }

            req.ProjectTo(item);

            await _repository.AddOrUpdateAsync(item);
        }
コード例 #2
0
        public async Task <IHttpActionResult> UpdateSchoolYear([FromBody] UpdateSchoolYearRequest request)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.UpdateAsync(request);

                    await _service.CommitAsync();

                    return(Ok());
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                await _service.RollbackAsync();

                return(BadRequest(GetError(ex)));
            }
        }
コード例 #3
0
 public static void ProjectTo(this UpdateSchoolYearRequest request, SchoolYear entity)
 {
     entity.Name     = request.Name;
     entity.IsClosed = request.IsClosed;
 }