Example #1
0
        public async Task <IHttpActionResult> Putphone(int id, phone phone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(phone).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!phoneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <ActionResult <Phone> > PostPhone(Phone phone)
        {
            _context.Phones.Add(phone);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPhone), new { id = phone.Id }, phone));
        }
Example #3
0
        public async Task <IActionResult> PutPhone(int id, Phone phone)
        {
            if (id != phone.PhoneId)
            {
                return(BadRequest());
            }

            _context.Entry(phone).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhoneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
 public virtual T Add(T newObj)
 {
     if (!CheckConnection())
     {
         return(default(T));
     }
     _context.Add <T>(newObj);
     _context.SaveChangesAsync().Wait();
     return(newObj);
 }
        public async Task <IActionResult> PutContactInfo(int id, [FromBody] ContactInfo contactInfo)
        {
            if (id != contactInfo.ContactInfoId)
            {
                return(BadRequest());
            }

            //_context.Entry(contactInfo).State = EntityState.Modified;

            try
            {
                if (new ContactInfoValidation().isMobilePhoneValid(contactInfo.Phone.MobilePhone))
                {
                    var dbContactInfo = _context.ContactInfos.Include(p => p.Phone).FirstOrDefault(s => s.ContactInfoId.Equals(id));

                    dbContactInfo.FirstName         = contactInfo.FirstName;
                    dbContactInfo.LastName          = contactInfo.LastName;
                    dbContactInfo.Address           = contactInfo.Address;
                    dbContactInfo.Email             = contactInfo.Email;
                    dbContactInfo.Phone.MobilePhone = contactInfo.Phone.MobilePhone;
                    dbContactInfo.Phone.HomePhone   = contactInfo.Phone.HomePhone;
                    dbContactInfo.Phone.WorkPhone   = contactInfo.Phone.WorkPhone;

                    //_context.ContactInfos.Update(contactInfo);

                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create(
            [Bind("Model,Brand,Memory,Rating,Smart,ReleaseDate")] Phone phone)

        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(phone);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(phone));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(phone));
        }
Example #7
0
 public async Task <int> SaveChangesAsync()
 {
     return(await PhoneDB.SaveChangesAsync());
 }