Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] PhoneBindingModel phone)
        {
            var existing = await Repository.GetGraphs(x => x.Id == id).FirstOrDefaultAsync();

            Mapper.Map <PhoneBindingModel, Phone>(phone, existing);
            await Repository.SaveAsUserAsync(UserId);

            var modified = Mapper.Map <PhoneViewModel>(existing);

            return(Ok(modified));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PostPhone(int id, [FromBody] PhoneBindingModel phone)
        {
            var newPhone = Mapper.Map <Phone>(phone);

            newPhone.ContactPersonId = id;
            Repository.AddOrUpdate(newPhone);
            await Repository.SaveAsUserAsync(UserId);

            var newlyAdded = await Repository.Get(x => x.Id == newPhone.Id).FirstOrDefaultAsync();

            if (newlyAdded != null)
            {
                var model = Mapper.Map <PhoneViewModel>(newlyAdded);
                return(Ok(model));
            }
            else
            {
                return(InternalServerError());
            }
        }