public async Task <IList <int> > AddContact(ContactDto contactDto) { IList <int> idContacts = new List <int>(); Contact contact; await _contactRepository.AddContact(new Contact { UserId = contactDto.UserId, FriendId = contactDto.FriendId }); await _contactRepository.UnitOfWork.Save(); contact = await _contactRepository.GetContact().LastOrDefaultAsync( ); idContacts.Add(contact.Id); await _contactRepository.AddContact(new Contact { UserId = contactDto.FriendId, FriendId = contactDto.UserId }); await _contactRepository.UnitOfWork.Save(); contact = await _contactRepository.GetContact().LastOrDefaultAsync(); idContacts.Add(contact.Id); return(idContacts); }
public void ShouldAddContacts() { Contact contact = new Contact(); contact.FirstName = "Pritam"; contact.LastName = "Ajmire"; contact.Email = "*****@*****.**"; contact.PhoneNumber = "8446100120"; contact.Status = "Active"; Contact dbContact = Repo.AddContact(contact); Assert.AreEqual(dbContact, contact); lastContactId = dbContact.Id; }
private void AddContactEvent() { if (selectedContact.ID == 0) { repository.AddContact(selectedContact); MessageBox.Show(SAVEMESSAGE, APPNAME); } else { repository.UpdateContact(selectedContact); MessageBox.Show(UPDATEMESSAGE, APPNAME); } LoadContacts(); SelectedContact = new Contact(); }
public async Task <Contact> AddContact(Contact contact) { var repoContact = MappingHelper.ToRepo(contact); var response = await _contactRepository.AddContact(repoContact); return(MappingHelper.ToDomain(response)); }
public int Add([FromBody] Contact contact) { if (String.IsNullOrWhiteSpace(contact.Name)) { throw new ArgumentException("Contact must have a title", "Name"); } if (String.IsNullOrWhiteSpace(contact.Email)) { throw new ArgumentException("Contact must have an email", "Email"); } if (String.IsNullOrWhiteSpace(contact.Phone)) { throw new ArgumentException("Contact must have a phone number", "Phone"); } try { var id = _contactRepository.AddContact(contact); _logger.LogInformation("Contact added: {0}, ID: {1}", contact.Name, contact.ContactId); return(id); } catch (Exception e) { _logger.LogError(e, "Error adding contact: " + contact.Name); return(0); } }
public IActionResult Post(string contact) { var status = false; string message = string.Empty; var data = JsonConvert.DeserializeObject <Contact>(contact); var userId = HttpContext.Session.GetString(Key.UserSession_Id); data.UserId = userId; try { _contactRepository.AddContact(data); _contactRepository.SaveChange(); status = true; message = ResultState.Add_SUCCESS; } catch { status = false; message = ResultState.Add_FALSE; } return(Json(new { status = status, message = message })); }
public static void addContact() { Console.WriteLine("Add: "); Console.Write("FirstName: "); string firstname = Console.ReadLine(); Console.Write("LastName: "); string lastName = Console.ReadLine(); bool sizenotequalto10 = true; int phoneno = 0; while (sizenotequalto10 == true) { Console.Write("PhoneNo: "); phoneno = int.Parse(Console.ReadLine()); if (phoneno.ToString().Length == 9) { sizenotequalto10 = false; } else { Console.WriteLine("Invalid Phone No"); } } Contact c = new Contact { FirstName = firstname, LastName = lastName, PhoneNo = phoneno }; contactRepo.AddContact(c); Console.WriteLine("------------Added Successfully------------"); Showlist(); }
public IActionResult Post(string contact) { var status = false; string message = string.Empty; var data = JsonConvert.DeserializeObject <Contact>(contact); try { if (User.Identity.IsAuthenticated) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; data.UserId = userId; _contactRepository.AddContact(data); _contactRepository.SaveChange(); status = true; message = ResultState.Add_SUCCESS; } } catch { status = false; message = ResultState.Add_FALSE; } return(Json(new { status = status, message = message })); }
public async Task <int> AddReservation(ReservationViewModel model) { try { Reservation reservation = _mapper.Map <Reservation>(model); //Finding contact by name to know if exits var tempContact = _repoContact.GetContactByName(model.ContactName); if (tempContact.Id == 0) { //Trying other way to map Contact contact = new Contact { Name = model.ContactName, PhoneNumber = model.PhoneNumber, Birth = model.Birth, ContactTypeId = model.ContactTypeId }; //Adding contact if not exists await _repoContact.AddContact(contact); } var result = await _repo.AddReservation(reservation); //Returning Reservation Id return(result); } catch (Exception ex) { throw ex; } }
public IActionResult Create(ContactCreateViewModel model) { Console.WriteLine(model.Photo); if (ModelState.IsValid) { string uniqueFileName = null; if (model.Photo != null) { string uploadsFolder = Path.Combine(this.hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Contact newContact = new Contact { Name = model.Name, Position = model.Position, Address = model.Address, Avatar = uniqueFileName, NickName = model.NickName, PhoneNumber = model.PhoneNumber, Email = model.Email }; _contactRepository.AddContact(newContact); return(RedirectToAction("details", new { id = newContact.Id })); } return(View()); }
public async Task <bool> BookAppointment(BookingRecord bookingRecord) { var removeTimePortion = new TimeSpan(0, 0, 0); bookingRecord.Date = bookingRecord.Date.Date + removeTimePortion; var timeSlotavailability = await _appointmentRepository.VerifyTimeSlotAvailable(bookingRecord); if (!timeSlotavailability) { // TODO: log time slot unavailable return(false); } var existingContact = await _contactRepository.CheckDuplicate(bookingRecord.contact); var contactID = existingContact.ID != 0 ? existingContact.ID : await _contactRepository.AddContact(bookingRecord.contact); var added = await _appointmentRepository.AddAppointment(bookingRecord, contactID); // TODO: log added successful return(added); }
public async Task <JsonResult> CreateContactAsync([FromBody] ContactCreateModel model) { Address address = new Address() { StreetAddress = model.StreetAddress, City = model.City, State = model.State, Country = model.Country, ZipCode = model.ZipCode }; Contact contact = new Contact() { Name = model.Name, Company = model.Company, ProfileImageUrl = model.ProfileImageUrl, Email = model.Email, Birthdate = Convert.ToDateTime(model.Birthdate), WorkPhoneNumber = model.WorkPhoneNumber, PersonalPhoneNumber = model.PersonalPhoneNumber, Address = address }; var createdContact = await _contactRepository.AddContact(contact); return(new JsonResult(PopulateContactViewModel(createdContact))); }
public async Task <IActionResult> AddContact(ContactViewModel contactViewModel, IFormFile file) { byte[] content = null; if (file != null) { using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); // Upload the file if less than 2 MB if (memoryStream.Length < 2097152) { content = memoryStream.ToArray(); } else { ModelState.AddModelError("File", "The file is too large."); } } } var applicationUser = await _userManager.GetUserAsync(HttpContext.User); int contactId = _contactRepository.AddContact(contactViewModel.Contact, content, applicationUser.Id); return(RedirectToAction("Index", "Contact", new { contactId = contactId })); }
public IActionResult CreateContact([FromBody] ContactCreationDto newContact) { if (newContact == null) { return(BadRequest()); } //ModelState.AddModelError("Description", "The provided description should be different from the name."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //TODO Implement unique email namd combination //map properties to entity framwork to pass to save method of contact repo var finalContact = Mapper.Map <Contact>(newContact); //call saving method _contactRepository.AddContact(finalContact); //verify that data layer persisted new contact if (!_contactRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } var contactForDataTransmission = Mapper.Map <Models.ContactsDto>(finalContact); return(CreatedAtRoute("GetContact", new { id = contactForDataTransmission.Id }, contactForDataTransmission)); }
public async Task <ActionResult> AddContact([FromBody] Contact contact) { try { if (contact == null) { return(BadRequest()); } else { if (contactRepository.GetEmail(contact.Email) != null) { var createdContact = await contactRepository.AddContact(contact); return(CreatedAtAction(nameof(GetContact), new{ id = createdContact.ContactId }, createdContact)); } else { return(StatusCode(StatusCodes.Status500InternalServerError, "Such a contact is already exist")); } } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error adding a new contact.")); } }
public JsonResult AddContact(Contact contact) { repoContact.AddContact(contact); repoContact.Save(); //Additional business logic can be called here: business.AnyMethod(); return(Json(new { status = "Contact save successfully" })); }
public async Task <IActionResult> AddContact([FromBody] Contact model) { if (ModelState.IsValid) { try { var contactId = await contactRepository.AddContact(model); if (contactId > 0) { return(Ok(contactId)); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public IActionResult AddContact(AddContactRequest request) { if (request == null) { return(BadRequest(new { message = "Please check your input" })); } return(Ok(contactRepository.AddContact(request))); }
public async Task<IActionResult> ExecuteAsync(SaveContact saveContact) { var newContact = _contactMapper.Map<Contact>(saveContact); int newContactID = await _contactRepository.AddContact(newContact); return new CreatedAtActionResult("GetContactById", "Contacts", new {id = newContactID }, newContact); }
public async Task <IActionResult> ApprovalApplyRequest(int userId, int applierId, CancellationToken token) { var request = await _contactApplyRequestRepository.ApprovalAsync(userId, applierId, token); if (!request) { return(BadRequest()); } UserIdentity applier = await _userService.GetBaseUserInfoAsync(applierId); await _contactReository.AddContact(UserIdentity.UserId, applier, token); UserIdentity userInfo = await _userService.GetBaseUserInfoAsync(UserIdentity.UserId); await _contactReository.AddContact(applierId, userInfo, token); return(Ok()); }
public void AddContact(Guid personId, Guid contactPersonId) { _contactRepo.AddContact( new Contact() { FirstPersonId = personId, SecondPersonId = contactPersonId }); }
public ActionResult AddContact(Contact contact) { if (!ModelState.IsValid) { return(View(contact)); } Repo.AddContact(contact); return(RedirectToAction("Contacts")); }
public async Task <IActionResult> ApprovalApplyRequest(int applierId, CancellationToken cancellationToken) { var result = await _contactApplyRequestRepository.ApprovalAsync(new UserIdentity().UserId, applierId, cancellationToken); if (!result) { return(BadRequest()); } var applier = await _userService.GetBaseUserInfoAsync(applierId); var userinfo = await _userService.GetBaseUserInfoAsync(new UserIdentity().UserId); await _contactRepository.AddContact(new UserIdentity().UserId, applier, cancellationToken); await _contactRepository.AddContact(applierId, userinfo, cancellationToken); return(Ok()); }
public IActionResult Index(Contact contact) { if (ModelState.IsValid) { _contactRepository.AddContact(contact); return(RedirectToAction("ContactComplete")); } return(View(contact)); }
public IActionResult CreateContact(Contact contact) { if (!ModelState.IsValid) { return(View(contact)); } var ContactId = contactRepository.AddContact(contact); return(RedirectToAction("CreatePhoneContact", new { contactid = ContactId })); }
public HttpResponseMessage PostContact(Contact contact) { contact = _contactRepository.AddContact(contact); var response = Request.CreateResponse <Contact>(HttpStatusCode.Created, contact); string uri = Url.Link("GetContactById", new { Id = contact.Id }); response.Headers.Location = new Uri(uri); return(response); }
public IHttpActionResult PostContact(Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } contact = Repo.AddContact(contact); return(CreatedAtRoute("DefaultApi", new { id = contact.Id }, contact)); }
public async Task <int> AddContact(ContactDto contact) { try { return(await _contactRepository.AddContact(ContactMapper.MapFromDto(contact))); } catch (ArgumentException) { throw; } }
public IActionResult PostContact([FromBody] Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _contactRepository.AddContact(contact); return(CreatedAtAction(nameof(GetContacts), new { id = contact.ContactId }, contact)); }
public IActionResult Index(Contact contact) { if (ModelState.IsValid) { _contactRepository.AddContact(contact); ViewBag.contact = _contactRepository.GetAllContacts(); return(RedirectToAction("Index", "Home")); } ViewBag.contact = _contactRepository.GetAllContacts(); return(View()); }