Пример #1
0
        public ActionResult <ContactModel> CreateContact(ContactForManipulationModel contact)
        {
            var contactEntity = _mapper.Map <Entities.Contact>(contact);

            _contactsRepository.AddContact(contactEntity);
            _contactsRepository.Save();

            var contactToReturn = _mapper.Map <ContactModel>(contactEntity);

            return(CreatedAtRoute("GetContact",
                                  new { contactId = contactToReturn.Id },
                                  contactToReturn));
        }
Пример #2
0
        public async Task <IActionResult> AddContact(ContactToAddDTO contactToAddDTO)
        {
            if (await _contactRepo.ContactExists(contactToAddDTO.Name))
            {
                return(BadRequest("Contact already exists"));
            }

            var phoneNumberList = new List <PhoneNumber>();

            foreach (var phoneNumber in contactToAddDTO.PhoneNumbers)
            {
                phoneNumberList.Add(new PhoneNumber()
                {
                    Number = phoneNumber
                });
            }

            var contactToAdd = new Contact
            {
                Name         = contactToAddDTO.Name,
                Email        = contactToAddDTO.Email,
                PhoneNumbers = phoneNumberList
            };

            var createdContact = await _contactRepo.AddContact(contactToAdd);


            return(Ok(createdContact));
        }
Пример #3
0
        public async Task <ActionResult> Post([FromBody] Contact contact)
        {
            await _repo.AddContact(contact);

            var uri = $"http://localhost:5000/api/v1/contactos/{contact.ContactId}";

            return(Created(uri, contact));
        }
Пример #4
0
        public JsonResult Create(ContactViewModel contactViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false }));
            }

            var contact = _contactsRepository.AddContact(contactViewModel.ToModel());

            return(Json(new { success = true, contact = contact.ToViewModel() }));
        }
Пример #5
0
        private void OnSave()
        {
            UpdateStudent(Student, _editingStudent);

            //Update Student Table
            if (EditMode)
            {
                _studentsRepository.UpdateStudent(_editingStudent);
            }
            else
            {
                _studentsRepository.AddStudent(_editingStudent);
            }

            //Update Contacts
            foreach (Contact contact in AddedContacts)
            {
                _contactsRepository.AddContact(contact);
            }
            foreach (Contact contact in DeletedContacts)
            {
                _contactsRepository.DeleteContact(contact.ContactID);
            }

            //Update Biometrics
            foreach (RelBiometric relBiometric in AddedRelBiometrics)
            {
                _relBiometricsRepository.AddRelBiometric(relBiometric);
            }
            foreach (Biometric biometric in DeletedBiometrics)
            {
                _relBiometricsRepository.DeleteRelBiometric(biometric.FingerID);
                _biometricsRepository.DeleteBiometric(biometric.FingerID);
            }

            //Update Groups
            #region Not used
            foreach (RelOrganization group in AddedGroups)
            {
                _relOrganizationsRepository.AddRelOrganization(group);
            }
            foreach (RelOrganization group in DeletedGroups)
            {
                _relOrganizationsRepository.DeleteRelOrganization(group.RelOrganizationID);
            }
            #endregion


            SelectedImage = null;
            Done();
        }
Пример #6
0
 //POST api/contacts
 public HttpResponseMessage Post([FromBody] Contact contact)
 {
     try
     {
         BaseResponse <bool> response = new BaseResponse <bool>();
         response.Data = _contactRepository.AddContact(contact);
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception ex)
     {
         BaseResponse <BasicError> response = new BaseResponse <BasicError>();
         response.Errors = new BasicError(ErrorCodes.TechnicalError.ToString(), ex.Message);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
     }
 }
Пример #7
0
        public async Task <BaseResponse> SendInvitationAsync(string userId, string invitedUserName)
        {
            if (invitedUserName == null)
            {
                return(new ErrorResponse(new ArgumentNullException($"{nameof(invitedUserName)} cannot be null!")));
            }

            var invitedUserResponse = await _userService.GetUser(invitedUserName);

            var invitedUser = (invitedUserResponse as SuccessResponse <ApplicationUser>)?.Result;

            if (invitedUser == null)
            {
                return(invitedUserResponse);
            }

            if (invitedUser.Id == userId)
            {
                return(new ErrorResponse(new ApplicationException("Cannot send invitation to itself!")));
            }

            var myContactsResponse = GetPotentionalContacts(userId, invitedUserName);
            var myContacts         = (myContactsResponse as SuccessResponse <List <Contact> >)?.Result;

            if (myContacts == null)
            {
                return(myContactsResponse);
            }

            if (myContacts.All(c => c.UserName != invitedUserName))
            {
                return(new ErrorResponse(new ApplicationException("Contact already exists!")));
            }

            var newContact = new Data.Models.Contact
            {
                CreateDate    = DateTimeOffset.UtcNow,
                RequestedById = userId,
                RequestedToId = invitedUser.Id,
                Status        = Data.Models.InvitationStatuses.PendingAcceptance
            };

            _contactsRepository.AddContact(newContact);

            var result = LocalMapper.Map <Contact>(newContact);

            return(new SuccessResponse <Contact>(result));
        }
Пример #8
0
        public async Task <IActionResult> AddContact([FromBody] Contacts model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var Id = await contactsRepository.AddContact(model);

                    if (Id > 0)
                    {
                        return(Ok(Id));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
 public void AddContact(Contact contact)
 {
     _contactsRepository.AddContact(contact);
 }
Пример #10
0
 public void WriteContactForSpecifiedItem(ContactDto contactDto)
 {
     _commonRepo.AddContact(_mapper.Map <ContactDto, Contact>(contactDto));
 }
Пример #11
0
 public async Task <bool> AddContact(ContactViewModel model)
 {
     return(await _webSiteRepository.AddContact(model));
 }
 public void AddContact(Item contact)
 {
     cache.AddContact(contact);
     SubmitChanges();
 }
        public async Task <ActionResult> AddSave(PhoneContactModel phoneContact)
        {
            await _contactsRepository.AddContact(phoneContact);

            return(RedirectToAction("Index"));
        }