public IHttpActionResult PutPhone(int id, Phone phone)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != phone.PhoneID)
            {
                return BadRequest();
            }

            try
            {
                db.UpdatePhone(phone);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhoneExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        public Phone AddPhone(Phone phone)
        {
            db.Phones.Add(phone);
            db.SaveChanges();

            return phone;
        }
Esempio n. 3
0
        public Phone Create(Phone oPhone)
        {
            if (oPhone != null)
            {
                return oPhoneRepo.CreatePhone(oPhone);
            }

            return null;
        }
        public IHttpActionResult PostPhone(Phone phone)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.CreatePhone(phone);

            return CreatedAtRoute("DefaultApi", new { id = phone.PhoneID }, phone);
        }
Esempio n. 5
0
        public void UpdatePhone(int id, Phone phone)
        {
            db.Entry(phone).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Converts this instance of <see cref="PhoneDTO"/> to an instance of <see cref="Phone"/>.
        /// </summary>
        /// <param name="dto"><see cref="PhoneDTO"/> to convert.</param>
        public static Phone ToEntity(this PhoneDTO dto)
        {
            if (dto == null) return null;

            var entity = new Phone();

            entity.PhoneID = dto.PhoneID;
            entity.CountryID = dto.CountryID;
            entity.Number = dto.Number;
            entity.Ext = dto.Ext;
            entity.PhoneTypeID = dto.PhoneTypeID;

            dto.OnEntity(entity);

            return entity;
        }
Esempio n. 7
0
        public Phone CreatePhone(Phone oPhone)
        {
            Phone oPhoneReturn = null;

            using (DBContext)
            {
                try
                {
                    oPhoneReturn = DBContext.Phones.Add(oPhone);
                    DBContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    //Log Exception.
                }
            }

            return oPhoneReturn;
        }
Esempio n. 8
0
        public Phone UpdatePhone(Phone oPhone)
        {
            Phone oPhoneReturn = null;
            if (oPhone != null && oPhone.PhoneID > 0)
            {
                using (DBContext)
                {
                    Phone u = this.GetPhoneByID(oPhone.PhoneID);

                    if (u != null)
                    {
                        Mapper.Map<Phone, Phone>(oPhone, u);
                        DBContext.SaveChanges();
                        oPhoneReturn = u;
                    }
                }
            }

            return oPhoneReturn;
        }
Esempio n. 9
0
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="entity"><see cref="Phone"/> converted from <see cref="PhoneDTO"/>.</param>
 static partial void OnEntity(this PhoneDTO dto, Phone entity);