public async Task <IActionResult> Edit(int id, ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } // Fetch Contact from DB to get OwnerID. var contact = await _context.Contact.SingleOrDefaultAsync(m => m.ContactId == id); if (contact == null) { return(NotFound()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, contact, ContactOperations.Update); if (!isAuthorized.Succeeded) { return(new ChallengeResult()); } contact = ViewModel_to_model(contact, editModel); _context.Update(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
private void OnEdit(object sender, RoutedEventArgs e) { //************************************************************************************************************************************** // Edit button clicked on Favorite/All Contacts list. User can change username, email, avatar from this dialog box. //************************************************************************************************************************************** if (!ServiceManager.Instance.ContactService.IsEditing()) { var contact = ((ToggleButton)sender).Tag as VATRPContact; if (contact != null) { ContactEditViewModel model = new ContactEditViewModel(false, contact.RegistrationName, contact.Avatar); model.ContactName = contact.Fullname; var contactEditView = new ContactEditView(model); Nullable <bool> dialogResult = contactEditView.ShowDialog(); if (dialogResult != null && dialogResult.Value) { if (model.AvatarChanged) { contact.Avatar = string.Empty; } ServiceManager.Instance.ContactService.EditLinphoneContact(contact, model.ContactName, model.ContactSipAddress); } } } }
public IActionResult CreateContact([FromBody] ContactEditViewModel contact) { var model = mapper.Map <ContactEditViewModel, ContactModel>(contact); var result = contactService.SaveContact(model); return(CreatedAtAction("GetContact", new { id = result.Id }, mapper.Map <ContactModel, ContactDetailViewModel>(result))); }
public async Task <IActionResult> Create(ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } var contact = ViewModel_to_model(new Contact(), editModel); contact.OwnerID = _userManager.GetUserId(User); var isAuthorized = await _authorizationService.AuthorizeAsync( User, contact, Operations.Create); if (!isAuthorized.Succeeded) { return(new ChallengeResult()); } _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id, ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } var contact = await _context.Contact.SingleOrDefaultAsync(m => m.ContactId == id); if (contact == null) { return(NotFound()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, contact, ContactOperations.Update); if (!isAuthorized) { return(new ChallengeResult()); } contact = ViewModel_to_model(contact, editModel); if (contact.Status == ContactStatus.Approved) { var canApprove = await _authorizationService.AuthorizeAsync(User, contact, ContactOperations.Approve); if (!canApprove) { contact.Status = ContactStatus.Submitted; } } _context.Update(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Put(int id, [FromBody] ContactEditViewModel vm) { var contact = await dbContext.Set <Contact>().FindAsync(id); if (contact == null) { return(NotFound()); } if (ModelState.IsValid) { if (vm.CompanyId.HasValue && vm.CompanyId != contact.CompanyId) { var company = await dbContext.Set <Company>().FindAsync(vm.CompanyId.Value); if (company == null) { ModelState.AddModelError(nameof(ContactListViewModel.CompanyId), "Company not found."); return(BadRequest(ModelState)); } } vm.ApplyTo(contact); await dbContext.SaveChangesAsync(); return(AcceptedAtRoute("GetContactById", new { id = contact.Id }, new ContactListViewModel(contact))); } else { return(BadRequest(ModelState)); } }
private ContactEditViewModel Model_to_viewModel(Contact contact) { var editModel = new ContactEditViewModel() { Email = contact.Email }; return(editModel); }
public IActionResult UpdateContact(int id, [FromBody] ContactEditViewModel contact) { var model = mapper.Map <ContactEditViewModel, ContactModel>(contact); model.Id = id; var result = contactService.SaveContact(model); return(Ok(mapper.Map <ContactModel, ContactDetailViewModel>(result))); }
private Contact ViewModelMapperToModel(ContactEditViewModel editModel, Contact contact) { contact.Address = editModel.Address; contact.City = editModel.City; contact.Email = editModel.Email; contact.Name = editModel.Name; contact.State = editModel.State; contact.Zip = editModel.Zip; return(contact); }
public async Task <IActionResult> Edit(int id) { var contact = await _ContactsService.GetContactByIdAsync(id); ContactEditViewModel model = contact != null ? contact.ToEditViewModel() : new ContactEditViewModel(); return(View(model)); }
public ActionResult Edit(ContactEditViewModel model) { ContactViewModel updateModel = contactsDB.Where(c => c.Id == model.Id).FirstOrDefault(); updateModel.Address = model.Address; updateModel.Name = model.Name; updateModel.Phone = model.Phone; updateModel.Changed = DateTime.Now; return(RedirectToAction("Details", updateModel)); }
public async Task <IActionResult> Edit(ContactEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } await _ContactsService.UpdateContactAsync(model); return(RedirectToAction("List")); }
public ViewResult Edit(int id) { Contact contact = _contactsRepository.GetContact(id); ContactEditViewModel editContactViewModel = new ContactEditViewModel() { Contact = contact, PageTitle = "Edit Contact" }; return(View(editContactViewModel)); }
//private bool ContactExists(int id) //{ // return _context.Contact.Any(e => e.ContactId == id); //} private static Contact ViewModelToModel(Contact contact, ContactEditViewModel editModel) { contact.Last = editModel.Last; contact.Email = editModel.Email; contact.Name = editModel.Name; contact.Position = editModel.Position; contact.Description = editModel.Description; contact.Phone = editModel.Phone; contact.OpenHr = editModel.OpenHr; contact.CloseHr = editModel.CloseHr; return(contact); }
public async Task <IActionResult> Create(ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } var contact = ViewModel_to_model(new Contact(), editModel); _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Edit(Guid id) { ContactViewModel retrievedModel = contactsDB.Where(c => c.Id == id).FirstOrDefault(); ContactEditViewModel model = new ContactEditViewModel() { Id = retrievedModel.Id, Address = retrievedModel.Address, Name = retrievedModel.Name, Phone = retrievedModel.Phone, }; return(View(model)); }
private ContactEditViewModel Model_to_viewModel(Contact contact) { var editModel = new ContactEditViewModel(); editModel.ContactId = contact.ContactId; editModel.Address = contact.Address; editModel.City = contact.City; editModel.Email = contact.Email; editModel.Name = contact.Name; editModel.State = contact.State; editModel.Zip = contact.Zip; return(editModel); }
public virtual async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var viewModel = new ContactEditViewModel(); viewModel.Contact = await _context.GetByIdAsync <Contact>(id); viewModel.Replies = await _context.GetAsync <ContactReply>(m => m.ContactId == id); return(View(viewModel)); }
private ContactEditViewModel Model_to_viewModel(Contact contact) { var editModel = new ContactEditViewModel { ContactId = contact.ContactId, Address = contact.Address, City = contact.City, Email = contact.Email, Name = contact.Name, State = contact.State, Zip = contact.Zip }; return(editModel); }
public async Task <IActionResult> Edit(ContactEditViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var currentUserId = _userManager.GetUserId(User); var isAuthorized = await AuthorizationService.AuthorizeAsync(User, vm, ContactOperations.Update); if (!isAuthorized.Succeeded) { return(Forbid()); } await _mediator.Send(new ContactEdit(vm)); return(RedirectToAction(nameof(Index))); }
private static ContactEditViewModel ModelToViewModel(Contact contact) { var editModel = new ContactEditViewModel() { ContactId = contact.ContactId, Last = contact.Last, Email = contact.Email, Name = contact.Name, Position = contact.Position, Description = contact.Description, Phone = contact.Phone, OpenHr = contact.OpenHr, CloseHr = contact.CloseHr }; return(editModel); }
public ContactDetailPage(ContactViewModel contact) { if (contact == null) { throw new ArgumentNullException(); } IPageService pageService = new PageService(); string accessToken = (Application.Current as App).AccessToken; ContactEditViewModel contactVM = new ContactEditViewModel(Navigation, pageService, accessToken) { Contact = contact }; BindingContext = contactVM; InitializeComponent(); }
public ActionResult ContactRelationshipList(ContactEditViewModel contactEditVM) { Logger.Info(_logMsg.Clear().SetPrefixMsg("Get ContactRelationship List") .Add("JsonContactRelationship", contactEditVM.JsonContactRelationship).ToInputLogString()); try { Logger.Info(_logMsg.Clear().SetPrefixMsg("Get ContactRelationship List").ToSuccessLogString()); return(PartialView("~/Views/Contact/_ContactRelationshipList.cshtml", contactEditVM)); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("Get ContactRelationship List").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
public async Task <IActionResult> Edit(int id, ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } // Fetch Contact from DB to get OwnerID. var contact = await _context.Contacts.SingleOrDefaultAsync(m => m.ContactId == id); if (contact == null) { return(NotFound()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, contact, Operations.Update); if (!isAuthorized.Succeeded) { return(new ChallengeResult()); } contact = ViewModel_to_model(contact, editModel); if (contact.Status == ContactStatus.Approved) { // If the contact is updated after approval, // and the user cannot approve set the status back to submitted var canApprove = await _authorizationService.AuthorizeAsync(User, contact, Operations.Approve); if (!canApprove.Succeeded) { contact.Status = ContactStatus.Submitted; } } _context.Update(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IActionResult Edit(int id) { var contactFromDb = _contactDatabase.GetContact(id); var contact = new ContactEditViewModel() { FirstName = contactFromDb.FirstName, LastName = contactFromDb.LastName, PhoneNumber = contactFromDb.PhoneNumber, Address = contactFromDb.Address, Email = contactFromDb.Email, Description = contactFromDb.Description, BirthDate = contactFromDb.BirthDate, ContactType = contactFromDb.ContactType, PhotoUrl = contactFromDb.PhotoUrl, }; return(View(contact)); }
public async Task UpdateContactAsync(ContactEditViewModel model) { var contact = await GetContactByIdAsync(model.Id); contact.Firstname = model.Firstname; contact.Middlename = model.Middlename; contact.Lastname = model.Lastname; contact.CellPhone = model.CellPhone; contact.HomePhone = model.HomePhone; contact.DateOfBirth = model.DateOfBirth; contact.Email = model.Email; contact.Occupation = model.Occupation; contact.Suffix = model.Suffix; if (contact.ContactAddress == null) { contact.ContactAddress = new ContactAddress(); } contact.ContactAddress.Address1 = model.Address1; contact.ContactAddress.Address2 = model.Address2; contact.ContactAddress.City = model.City; contact.ContactAddress.State = model.State; contact.ContactAddress.Zip = model.Zip; bool userUploadedAnImage = (model.Photo != null); if (userUploadedAnImage) { if (contact.AlbumImage == null) { contact.AlbumImage = new AlbumImage(); } var ms = new MemoryStream(); model.Photo.CopyTo(ms); contact.AlbumImage.Filename = model.Photo.FileName; contact.AlbumImage.Filetype = model.Photo.ContentType; contact.AlbumImage.ImageBytes = ms.ToArray(); } await _ContactsRepository.SaveChangesAsync(); }
public IActionResult Update([FromForm] ContactEditViewModel vm, [FromRoute] int id) { if (!TryValidateModel(vm)) { return(View(vm)); } _contactDatabase.Update(id, new Contact { Name = vm.Name, Surname = vm.Surname, Email = vm.Email, BirthDate = vm.BirthDate, TelNr = vm.TelNr, Address = vm.Address, Annotation = vm.Annotation }); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, ContactEditViewModel editModel) { if (!ModelState.IsValid) { return(View(editModel)); } var contact = await _context.Contact.SingleOrDefaultAsync(m => m.ContactId == id); if (contact == null) { return(NotFound()); } contact = ViewModel_to_model(contact, editModel); _context.Update(contact); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IActionResult Edit([FromRoute] int id, ContactEditViewModel vm) { if (!TryValidateModel(vm)) { return(View()); } var contact = new Contact { FirstName = vm.FirstName, LastName = vm.LastName, Adress = vm.Adress, Birthdate = vm.Birthdate, Email = vm.Email, Phone = vm.Phone, Description = vm.Description }; var dbContact = _contactenDatabase.GetContact(id); if (vm.Photo == null) { contact.PhotoUrl = dbContact.PhotoUrl; } else { if (!string.IsNullOrEmpty(dbContact.PhotoUrl)) { DeletePhoto(dbContact.PhotoUrl); } string uniqueFileName = UploadPhoto(vm.Photo); contact.PhotoUrl = "/photos/" + uniqueFileName; } _contactenDatabase.Update(id, contact); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int id, ContactEditViewModel contactEditViewModel) { try { var contactUpdate = _contactQueries.GetOneById(id); contactUpdate.Id = contactEditViewModel.Id; contactUpdate.FirstName = contactEditViewModel.FirstName; contactUpdate.LastName = contactEditViewModel.LastName; contactUpdate.Email = contactEditViewModel.Email; contactUpdate.DateUpdated = DateTime.Now; var account = _accountQueries.GetOneById(contactEditViewModel.AccountOnSelect); contactUpdate.Accounts.Add(account); _contactQueries.Save(contactUpdate); return(RedirectToAction("Index")); } catch { return(View()); } }
private void ExecuteAddCommand(object obj) { if (!ServiceManager.Instance.ContactService.IsEditing()) { ContactEditViewModel model = new ContactEditViewModel(true, string.Empty, string.Empty); var contactEditView = new ContactEditView(model); var dialogResult = contactEditView.ShowDialog(); if (dialogResult != null && dialogResult.Value) { var contact = ServiceManager.Instance.ContactService.FindContact(new ContactID(model.ContactSipAddress, IntPtr.Zero)); if (contact != null && contact.Fullname == model.ContactName) return; ServiceManager.Instance.ContactService.AddLinphoneContact(model.ContactName, model.ContactSipUsername, model.ContactSipAddress); } } }
public ContactEditView(ContactEditViewModel viewModel) : this() { _viewModel = viewModel; DataContext = _viewModel; }
public void AddNewContact(HistoryCallEventViewModel callEventViewModel) { if (!ServiceManager.Instance.ContactService.IsEditing()) { var remote = callEventViewModel.CallEvent.RemoteParty.TrimSipPrefix(); ContactEditViewModel model = new ContactEditViewModel(false, remote, string.Empty); model.ContactName = callEventViewModel.DisplayName; var contactEditView = new com.vtcsecure.ace.windows.Views.ContactEditView(model); var dialogResult = contactEditView.ShowDialog(); if (dialogResult != null && dialogResult.Value) { var contact = ServiceManager.Instance.ContactService.FindContact(new ContactID(model.ContactSipAddress, IntPtr.Zero)); if (contact != null && contact.Fullname == model.ContactName) return; ServiceManager.Instance.ContactService.AddLinphoneContact(model.ContactName, model.ContactSipUsername, model.ContactSipAddress); } } }