Пример #1
0
        public static AttendeeModel Create(Attendee obj)
        {
            if (obj == null)
                return null;

            var model = new AttendeeModel()
            {
                Id = obj.Id,
                Code  = obj.Code,
                EmailAddress = obj.EmailAddress,
                JobTitle = obj.JobTitle,
                Name =obj.Name
            };

            var proposals = new List<TalkProposalModel>();
            if (obj.TalkProposals != null)
            {
                foreach (var talkProposalReference in obj.TalkProposals)
                {
                    proposals.Add(Create(talkProposalReference));
                }
            }
            model.TalkProposals = proposals;

            return model;
        }
Пример #2
0
        public async Task<IHttpActionResult> PutAttendees(int id, AttendeeModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != model.Id)
            {
                return BadRequest();
            }

            try
            {
                var attendee = _attendeeService.Find(id);
                attendee = ObjectFactory.Parse(model, attendee);
                attendee.ObjectState = ObjectState.Modified;
                _attendeeService.Update(attendee);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttendeesExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #3
0
        internal static Entities.Attendee Parse(AttendeeModel model, Attendee obj)
        {
            if (model == null)
            {
                return null;
            }

            if (obj != null)
            {
                obj.Name = model.Name;
                obj.JobTitle = model.JobTitle;
                obj.Code = model.Code;
                obj.EmailAddress = model.EmailAddress;

            }

            return obj;
        }
Пример #4
0
        public async Task<IHttpActionResult> PostAttendees(AttendeeModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var attendee = new Attendee();
            attendee = ObjectFactory.Parse(model, attendee);
            attendee.ObjectState = ObjectState.Added;
            _attendeeService.Insert(attendee);
            await _unitOfWork.SaveChangesAsync();

            model = ModelFactory.Create(attendee);
            return CreatedAtRoute("DefaultApi", new { id = model.Id }, model);
        }