示例#1
0
 public bool Validate(CreateVolunteerEventRequest requestToValidate)
 {
     return(string.IsNullOrEmpty(requestToValidate.EventName) ||
            string.IsNullOrEmpty(requestToValidate.StartDate.ToString()) ||
            string.IsNullOrEmpty(requestToValidate.StartTime.ToString()) ||
            string.IsNullOrEmpty(requestToValidate.EndTime.ToString()) ||
            string.IsNullOrEmpty(requestToValidate.AdminId.ToString())
            );
 }
        public ActionResult UpdateVolunteerEvent(int id, CreateVolunteerEventRequest updateRequest)
        {
            //if (id != volunteerEventToUpdate.Id)
            //{
            //    return BadRequest();
            //}

            var updateEvent = _repository.UpdateVolunteerEvent(id, updateRequest.EventName, updateRequest.Description, updateRequest.Location, updateRequest.StartDate, updateRequest.StartTime, updateRequest.EndTime, updateRequest.AdminId);

            return(Ok(updateEvent));
        }
        public ActionResult AddVolunteerEvent(CreateVolunteerEventRequest createRequest)
        {
            if (_validator.Validate(createRequest))
            {
                return(BadRequest(new { error = "please enter all fields" }));
            }

            var newVolunteerEvent = _repository.AddVolunteerEvent(createRequest.EventName, createRequest.Description, createRequest.Location, createRequest.StartDate, createRequest.StartTime, createRequest.EndTime, createRequest.AdminId);

            return(Created($"api/volunteerEvent/{newVolunteerEvent.Id}", newVolunteerEvent));
        }