Пример #1
0
        public IHttpActionResult Post([FromBody] IEnumerable <CreateSponsorshipModel> createSponsorshipModels)
        {
            if (createSponsorshipModels == null || !createSponsorshipModels.Any() || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_createSponsorshipsValidator.IsValid(createSponsorshipModels))
            {
                return(_createSponsorshipsValidator.BadRequest());
            }

            foreach (var sponsorship in createSponsorshipModels.Select(s => _mapper.Map <Sponsorship>(s)))
            {
                sponsorship.DateCreated  = DateTime.UtcNow;
                sponsorship.DateModified = DateTime.UtcNow;
                sponsorship.Uid          = Guid.NewGuid();
                _sponsorshipRepository.Add(sponsorship);
            }

            _sponsorshipRepository.SaveChanges();

            return(Ok());
        }
Пример #2
0
 public Sponsorship Add(Sponsorship model)
 {
     _sponsorshipRepository.Add(model);
     return(model);
 }