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);
        }
        public Phone AddPhone(Phone phone)
        {
            db.Phones.Add(phone);
            db.SaveChanges();

            return phone;
        }
Exemple #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);
        }
        public void UpdatePhone(int id, Phone phone)
        {
            db.Entry(phone).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Exemple #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;
        }
        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;
        }
        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;
        }
Exemple #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);