示例#1
0
 public IHttpActionResult Create([FromBody] CreateShiftDto shift)
 {
     if (shift == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         _shiftService.Create(shift);
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
        public void Create(CreateShiftDto dto)
        {
            var shift = new Shift
            {
                Title = dto.Title
            };

            _shiftRepository.Insert(shift);
        }
示例#3
0
        public ActionResult <ShiftDto> CreateShift(Guid personId, Guid projectId, [FromBody] CreateShiftDto dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                if (!_db.Person.BelongsToUser(personId, HttpContext))
                {
                    return(Forbid());
                }
                if (_db.Participation.GetRole(personId, projectId)?.CalendarWrite != true)
                {
                    return(Forbid());
                }
                if (_db.Participation.GetEligibilityByCategory(personId, projectId, dto.CategoryId)?.ShiftsWrite != true)
                {
                    return(Forbid());
                }

                var category = _db.Category
                               .FindByCondition(x => x.Id == dto.CategoryId && x.ProjectId == projectId)
                               .SingleOrDefault();
                if (category == null)
                {
                    return(BadRequest());
                }

                var shift = _mapper.Map <Shift>(dto);

                shift.Status          = ShiftStatus.Draft.ToString();
                shift.Mode            = ShiftMode.Open.ToString();
                shift.CalledOffReason = string.Empty;

                _db.Shift.Create(shift);
                _db.Save();

                return(Ok(_db.Shift.GetFullShift(_mapper, shift.Id, personId)));
            }
            catch (Exception e)
            {
                _logger.LogError($"ERROR in CreateShift: {e.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }