Exemple #1
0
        public async Task <IActionResult> PutAdditionalPhone(string id, AdditionalPhone additionalPhone)
        {
            if (id != additionalPhone.Phone)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #2
0
        public async Task <ActionResult <ContactDTO> > Create(ContactDTO contactDto)
        {
            contactDto.Id = null;
            var contact = mapper.Map <Contact>(contactDto);

            try
            {
                context.Contacts.Add(contact);
                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                if (await PhoneTaken(contactDto.Phone))
                {
                    ModelState.AddModelError("phone", "This phone number is already taken!");
                    return(BadRequest(ModelState));
                }
                throw;
            }

            //return CreatedAtAction(nameof(GetByIdAsync), new { contact.Id }, contact);
            contactDto = mapper.Map <ContactDTO>(contact);

            await hubContext.Clients.All.SendAsync("notification", "Contact created!", $"{contactDto.Name} {contactDto.Surname}");

            return(Created($"api/v1/contacts/{contact.Id}", contactDto));
        }
Exemple #3
0
        public async Task <IActionResult> PutContact(string id, Contact contact)
        {
            if (id != contact.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> Create(AdditionalPhoneDTO additionalPhoneDTO)
        {
            var phone = mapper.Map <AdditionalPhone>(additionalPhoneDTO);

            var contact = await context.Contacts.FindAsync(phone.ContactId);

            if (contact == null)
            {
                return(BadRequest("Contact does not exists!"));
            }

            context.AdditionalPhones.Add(phone);
            await context.SaveChangesAsync();

            return(Accepted(phone));
        }
        public async Task <IActionResult> Logout(string refreshToken)
        {
            var token = context.RefreshTokens.Find(refreshToken);

            if (token != null)
            {
                context.RefreshTokens.Remove(token);
                await context.SaveChangesAsync();
            }
            return(NoContent());
        }
Exemple #6
0
 protected Task SaveAsync()
 {
     return(_db.SaveChangesAsync());
 }