public async Task <IActionResult> Update(ContactEditModel model) { if (ModelState.IsValid) { var contact = _mapper.Map <Contact>(model); await _contactService.UpdateAsync(contact); if (model.PropertyId.HasValue) { return(RedirectToAction("Details", "Property", new { id = model.PropertyId.Value })); } else if (model.CustomerId.HasValue) { return(RedirectToAction("Details", "Customer", new { id = model.CustomerId.Value })); } } if (Request.IsAjaxRequest()) { return(PartialView(model)); } else { return(View(model)); } }
public IHttpActionResult Edit(ContactEditModel theContact) { Reply reply = new Reply(); String json = ""; var userID = User.Identity.GetUserId(); //get user ID UserEmergency userEmergency = new UserEmergency(); userEmergency.UserProfileId = userID; userEmergency.EmergencyContactPhone = theContact.pre.EmergencyContactPhone; userEmergency.ECname = theContact.pre.ECname; UserEmergency newContact = new UserEmergency(); newContact.UserProfileId = userID; newContact.EmergencyContactPhone = theContact.now.EmergencyContactPhone; newContact.ECname = theContact.now.ECname; if (ModelState.IsValid) { //Check does the phone exist if not store Contactphone to table EmergencyContacts EmergencyContact thisContact = db.EmergencyContact.Find(newContact.EmergencyContactPhone); if (thisContact == null) { createNewContact(newContact.EmergencyContactPhone); } //Check whether old userEmergency exist var result = db.UserEmergency.Find(userEmergency.EmergencyContactPhone, userEmergency.UserProfileId); if (result == null) { reply.result = "failed"; reply.errors = "Contact do not exist"; return(BadRequest(JsonConvert.SerializeObject(reply))); } var checkNew = db.UserEmergency.Find(newContact.EmergencyContactPhone, newContact.UserProfileId); if (checkNew != null && newContact.EmergencyContactPhone != userEmergency.EmergencyContactPhone) { reply.result = "failed"; reply.errors = "The contact phone number already exist"; return(BadRequest(JsonConvert.SerializeObject(reply))); } db.UserEmergency.Remove(result); db.UserEmergency.Add(newContact); db.SaveChanges(); reply.result = "Edit success"; json = JsonConvert.SerializeObject(reply); reply.result = "contact create, edit success"; json = JsonConvert.SerializeObject(reply); return(Ok(json)); } reply.result = "failed"; reply.errors = "Data Type not validate"; json = JsonConvert.SerializeObject(reply); return(Ok(json)); }
public ContactEdit(T_E_CONTACT_CTC _Prospect = null) { InitializeComponent(); Model = new ContactEditModel(_Prospect); this.DataContext = Model; }
public IActionResult Edit(int id, ContactEditModel contact) { if (!TryValidateModel(contact)) { return(View(contact)); } var contactToDb = new Contact() { FirstName = contact.FirstName, LastName = contact.LastName, PhoneNumber = contact.PhoneNumber, Addres = contact.Address, Email = contact.Email, Description = contact.Description, BirthDate = contact.BirthDate }; //if (contact.Avatar != null) //{ // var bytes = GetBytesFromFile(contact.Avatar); // contactToDb.Avatar = bytes; //} if (contact.Avatar != null) { var uniqueFileName = Guid.NewGuid().ToString() + Path.GetExtension(contact.Avatar.FileName); var path = Path.Combine(_hostEnvironment.WebRootPath, "photos", uniqueFileName); Contact contactFromDb = _contactDatabase.GetContact(id); if (!string.IsNullOrEmpty(contactFromDb.PhotoUrl)) { var prevPath = Path.Combine(_hostEnvironment.WebRootPath, "photos", contactFromDb.PhotoUrl.Substring(8)); System.IO.File.Delete(prevPath); } using (var stream = new FileStream(path, FileMode.Create)) { contact.Avatar.CopyTo(stream); } contactToDb.PhotoUrl = "/photos/" + uniqueFileName; } else { Contact contactFromDb = _contactDatabase.GetContact(id); if (!string.IsNullOrEmpty(contactFromDb.PhotoUrl)) { contactToDb.PhotoUrl = contactFromDb.PhotoUrl; } } _contactDatabase.Update(id, contactToDb); return(RedirectToAction("Detail", new { Id = id })); }
public ActionResult AddCustomer([Bind(Include = "Id,FirstName,LastName")] ContactEditModel e) { if (!ModelState.IsValid) { return(View("AddCustomer", e)); } var contact = new ContactInstance { Contact = new Contacts() }; contact.UniqueId = GetRandom.String(); e.Update(contact); BusinessContact.SaveContactInstance(contact); return(RedirectToAction("Index")); }
public ActionResult EditCustomer([Bind(Include = "Id,FirstName,LastName")] ContactEditModel c) { if (!ModelState.IsValid) { return(View("EditCustomer", c)); } var contact = Contacts.Instance.Find(x => x.IsThisUniqueId(c.Id)); if (contact == null) { return(HttpNotFound()); } c.Update(contact); BusinessContact.UpdateContactInstance(contact); return(RedirectToAction("Index")); }
public IActionResult Create(ContactEditModel model) { if (ModelState.IsValid) { var newContact = new FoodContact(); newContact.Name = model.Name; newContact.Street = model.Street; newContact.Phone = model.Phone; newContact.City = model.City; newContact = _contactData.Add(newContact); return(RedirectToAction(nameof(Details), new { id = newContact.Id })); } else { return(View()); } }
public IActionResult Edit(int id) { var contactFromDb = _contactDatabase.GetContact(id); var contact = new ContactEditModel() { FirstName = contactFromDb.FirstName, LastName = contactFromDb.LastName, PhoneNumber = contactFromDb.PhoneNumber, Address = contactFromDb.Addres, Email = contactFromDb.Email, Description = contactFromDb.Description, BirthDate = contactFromDb.BirthDate, PhotoUrl = contactFromDb.PhotoUrl }; return(View(contact)); }
public async Task <ActionResult> SendMessage(ContactEditModel model) { if (!ModelState.IsValid) { return(Json(new { success = false, message = "Please correctly fill all the required fields." })); } if (!string.IsNullOrWhiteSpace(SiteSettings.ReCaptchaKey) && !string.IsNullOrWhiteSpace(SiteSettings.ReCaptchaSecret)) { var captchaResponse = await _captchaService.ValidateAsync(SiteSettings.ReCaptchaSecret, Request.Form["g-recaptcha-response"]); if (!captchaResponse.Success) { return(Json(new { success = false, message = string.Format("Captcha validation failed. ({0})", captchaResponse.ErrorCodes[0]) })); } } var from = new MailAddress(model.Email, model.Name); var mailMessage = new MailMessage() { From = from, To = { SiteSettings.ContactEmail }, Subject = model.Subject, Body = model.Message }; try { await _emailService.SendAsync(mailMessage, SiteSettings.SMTPHost, SiteSettings.SMTPPort, SiteSettings.SMTPUserName, SiteSettings.SMTPPassword, SiteSettings.SMTPEnableSSL); return(Json(new { success = true, message = "Your message has been successfully sent." })); } catch { return(Json(new { success = false, message = "An error occurred while sending your mail." })); } finally { mailMessage.Dispose(); } }
public ActionResult AddCustomer() { var b = new ContactEditModel(); return(View("AddCustomer", b)); }
public async Task <IActionResult> Edit([Required][FromForm] int id, ContactEditModel contactEditModel) { if (ModelState.IsValid) { IDbContextTransaction transaction = null; try { transaction = await lawyerDbContext.Database.BeginTransactionAsync(); StaticData staticData = await lawyerDbContext.StaticDatas.FindAsync(id); if (staticData == null) { throw new NullReferenceException(); } staticData.ContactEmail = contactEditModel.ContactEmail; staticData.ContactNumber = contactEditModel.ContactNumber; staticData.ContactHomeNumber = contactEditModel.ContactHomeNumber; IEnumerable <Text> adressTextAllLanguage = await lawyerDbContext.Texts .Where(m => m.Key == staticData.ContactAdressKey) .ToListAsync(); //Update texts all language for properties foreach (var item in contactEditModel.ContactAdresses) { Text adress = adressTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId); adress.TextContent = item.ContactAdress; } await lawyerDbContext.SaveChangesAsync(); transaction.Commit(); return(RedirectToAction(nameof(Index))); } catch (NullReferenceException exp) { ModelState.AddModelError("", exp.Message); } catch { transaction.Rollback(); ModelState.AddModelError("", "Some error occured. Please try again."); } finally { if (transaction != null) { transaction.Dispose(); } } } ContactViewModel contactViewModel = new ContactViewModel { Id = id, ContactEmail = contactEditModel.ContactEmail, ContactNumber = contactEditModel.ContactNumber, ContactAdresses = contactEditModel.ContactAdresses, Languages = await lawyerDbContext.Languages .AsNoTracking() .ToListAsync() }; return(View(contactViewModel)); }
public async Task <IActionResult> PutContact([FromRoute] int id, [FromBody] ContactEditModel contact) { //In this api we are using this type of model that complicates the code, because swagger generates the // scheme in the documentation more precise with this one if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var identity = HttpContext.User.Identity as ClaimsIdentity; if (identity != null) { IEnumerable <Claim> claims = identity.Claims; if (!(claims.FirstOrDefault().Value == id.ToString() || claims.FirstOrDefault().Value == "Administrator")) { return(BadRequest("You do not have permission to edit this Contact")); } } if (id != contact.ContactId) { return(BadRequest("No contactID added or the added one is wrong")); } var existingSkills = from u in _context.ContactSkillExpertise where u.ContactId == id select u; foreach (var item in existingSkills) { _context.ContactSkillExpertise.Remove(item); } foreach (var item in contact.ContactSkillExpertise) { if (_context.Skills.FirstOrDefault(x => x.SkillId == item.SkillId) == null) { return(BadRequest("One of the skills you are trying to add or modify does not exist as a base skill")); } ICollection <ContactSkillExpertiseModel> ContactSkillList = new HashSet <ContactSkillExpertiseModel>(); foreach (var itemm in contact.ContactSkillExpertise) { ContactSkillExpertiseModel ContactSkill = new ContactSkillExpertiseModel(); ContactSkill.ExpertiseLvlid = itemm.ExpertiseLvlid; ContactSkill.SkillId = itemm.SkillId; ContactSkillList.Add(ContactSkill); } _context.Contact.Update(new ContactModel() { ContactId = contact.ContactId, Firstname = contact.Firstname, Lastname = contact.Lastname, Fullname = contact.Fullname, Email = contact.Email, Address = contact.Address, MobileNum = contact.MobileNum, ContactSkillExpertise = ContactSkillList }); } try { await _context.SaveChangesAsync(); } catch (Exception e) { if (!ContactExists(id)) { return(NotFound("The record with id " + id + " does not exist in the database")); } else { return(NotFound(e.InnerException.Message)); } } return(Ok("Success")); }
public ActionResult Edit(ContactEditModel contactEditModel) { return(View()); }
public void EditContact(ContactEditModel model) { unitOfWork.ContactRepository.Update((Contacts)model); unitOfWork.Save(); }