public IHttpActionResult AddNewAdditionalContact([FromBody] AdditionalContact newAdditionalContact) { if (Equals(newAdditionalContact, null)) { return(BadRequest()); } var additionalContact = _unitOfWork.AdditionalContacts.Find(ac => ac.Email == newAdditionalContact.Email); if (additionalContact.Any()) { return(Content(HttpStatusCode.Conflict, "Contact with same email already exists.")); } try { _unitOfWork.AdditionalContacts.Add(newAdditionalContact); _unitOfWork.Complete(); _logger.SuccessfullyAddedServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(newAdditionalContact)); return(Ok(DtoHelper.CreateAdditionalContactDto(newAdditionalContact))); } catch (Exception ex) { _logger.FailedToCreateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(newAdditionalContact)); return(InternalServerError(ex)); } }
public ActionResult DeleteConfirmed(int id) { AnimalInfo animalInfo = db.AnimalInfo.Find(id); AnimalBehavior animalBehavior = db.AnimalBehavior.Find(id); AnimalHistory animalHistory = db.AnimalHistory.Find(id); ChipIdentification chipIdentification = db.ChipIdentification.Find(id); AdditionalContact additionalContact = db.AdditionalContact.Find(id); AdditionalPetInfo additionalPetInfo = db.AdditonalPetInfo.Find(id); Insurance insurance = db.Insurance.Find(id); MedicalHistory medicalHistory = db.MedicalHistory.Find(id); SecondaryContact secondaryContact = db.SecondaryContact.Find(id); TrackingOperations trackingOperations = db.TrackingOperations.Find(id); db.AnimalInfo.Remove(animalInfo); db.AnimalBehavior.Remove(animalBehavior); db.AnimalHistory.Remove(animalHistory); db.ChipIdentification.Remove(chipIdentification); db.AdditionalContact.Remove(additionalContact); db.AdditonalPetInfo.Remove(additionalPetInfo); db.Insurance.Remove(insurance); db.MedicalHistory.Remove(medicalHistory); db.SecondaryContact.Remove(secondaryContact); db.TrackingOperations.Remove(trackingOperations); db.SaveChanges(); return(RedirectToAction("Index")); }
public HttpStatusCode AddNewAdditionalContact(AdditionalContact newAdditionalContact) { var smAlreadyExists = _db.AdditionalContacts.Any(c => c.Email == newAdditionalContact.Email); if (smAlreadyExists) { return(HttpStatusCode.Conflict); } try { _db.AdditionalContacts.Add(newAdditionalContact); _db.SaveChanges(); _mongoMongoLogger.SuccessfullyAddedServerLog(HttpContext.Current.User, newAdditionalContact); return(HttpStatusCode.OK); } catch (Exception ex) { _mongoMongoLogger.FailedToCreateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, newAdditionalContact); return(HttpStatusCode.InternalServerError); } }
public ActionResult DeleteConfirmed(int id) { AdditionalContact additionalContact = db.AdditionalContact.Find(id); db.AdditionalContact.Remove(additionalContact); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,OwnerId,FirstName,LastName,PetRelation,PhoneNumber")] AdditionalContact additionalContact) { if (ModelState.IsValid) { db.Entry(additionalContact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(additionalContact)); }
/// <summary> /// Creates contacts and relations between provided announcement and /// contacts created or these stored in database that are the same as /// contacts given in view model. Note that context changes have to be saved /// to persist. /// </summary> /// <param name="announcementModel"></param> /// <param name="announcement"></param> /// <param name="context"></param> /// <returns></returns> public static async Task <int> CreateContactsForAnnoucement(SaveAnnouncemenModel announcementModel, Announcement announcement, AppDbContext context) { // Check if contacts defined in view model exist in database. List <AdditionalContact> newContacts = new List <AdditionalContact>(); List <AdditionalContact> dbContacts = new List <AdditionalContact>(); foreach (ContactPaymentItem item in announcementModel.Contacts) { AdditionalContact dbContact = await context.AdditionalContacts .Where(ac => ac.Type == item.Type) .Where(ac => ac.Data == item.Value) .SingleOrDefaultAsync(); // If such contact was found in database add it to list // else create new one. if (dbContact != null) { dbContacts.Add(dbContact); } else { newContacts.Add(new AdditionalContact() { Data = item.Value, Type = (byte)item.Type, }); } } // Add new contacts to context. await context.AdditionalContacts.AddRangeAsync(newContacts); // Create list of relations. List <AnnouncementToContact> announcementToContacts = new List <AnnouncementToContact>(); foreach (AdditionalContact contact in dbContacts) { announcementToContacts.Add(new AnnouncementToContact() { Announcement = announcement, AdditionalContact = contact, }); } foreach (AdditionalContact contact in newContacts) { announcementToContacts.Add(new AnnouncementToContact() { Announcement = announcement, AdditionalContact = contact, }); } // Add relations to contaxt. await context.AnnouncementToContacts.AddRangeAsync(announcementToContacts); return(0); }
public ActionResult Create([Bind(Include = "Id,OwnerId,FirstName,LastName,PetRelation,PhoneNumber")] AdditionalContact additionalContact) { if (ModelState.IsValid) { db.AdditionalContact.Add(additionalContact); db.SaveChanges(); return(RedirectToAction("Create", "AdditionalPetInfoes")); } return(View(additionalContact)); }
public IHttpActionResult UpdateAdditionalContact(AdditionalContact additionalContact) { if (Equals(additionalContact, null)) { return(BadRequest()); } var additionalContactToUpdate = _unitOfWork.AdditionalContacts.FindSingle(ac => ac.Id == additionalContact.Id); if (additionalContactToUpdate == null) { return(BadRequest()); } var additionalContactBeforeUpdate = DtoHelper.CreateAdditionalContactDto(additionalContact); try { if (ConcurrencyChecker.canSaveChanges(additionalContact.Version, additionalContactToUpdate.Version)) { additionalContactToUpdate.Name = additionalContact.Name; additionalContactToUpdate.Email = additionalContact.Email; additionalContactToUpdate.Telephone = additionalContact.Telephone; additionalContactToUpdate.System = additionalContact.System; additionalContactToUpdate.Fax = additionalContact.Fax; additionalContactToUpdate.Salutation = additionalContact.Salutation; additionalContactToUpdate.Version = additionalContact.Version + 1; additionalContactToUpdate.Role = additionalContact.Role; additionalContactToUpdate.NotificationSubscriber = additionalContact.NotificationSubscriber; additionalContactToUpdate.Active = additionalContact.Active; _unitOfWork.Complete(); _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, DtoHelper.CreateAdditionalContactDto(additionalContact), DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate)); return(Ok(DtoHelper.CreateAdditionalContactDto(additionalContactToUpdate))); } else { _logger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, additionalContact); return(Conflict()); } } catch (Exception ex) { _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, DtoHelper.CreateAdditionalContactDto(additionalContact)); return(InternalServerError()); } }
// GET: AdditionalContacts/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AdditionalContact additionalContact = db.AdditionalContact.Find(id); if (additionalContact == null) { return(HttpNotFound()); } return(View(additionalContact)); }
public bool Delete_AdditionalContacts(int AddContactID) { try { AdditionalContact objSms = _objSmsEntity.AdditionalContacts.FirstOrDefault(x => x.AdditionalContId == AddContactID); _objSmsEntity.DeleteObject(objSms); _objSmsEntity.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public HttpStatusCode UpdateAdditionalContact(AdditionalContact additionalContact) { var systemManagerToUpdate = _db.AdditionalContacts.SingleOrDefault(sm => sm.Id == additionalContact.Id); var systemManagerBeforeUpdate = DtoHelper.CreateAdditionalContactDto(systemManagerToUpdate); if (Equals(systemManagerToUpdate, null)) { return(HttpStatusCode.BadRequest); } try { if (ConcurrencyChecker.canSaveChanges(additionalContact.Version, systemManagerToUpdate.Version)) { systemManagerToUpdate.Name = additionalContact.Name; systemManagerToUpdate.Email = additionalContact.Email; systemManagerToUpdate.Telephone = additionalContact.Telephone; systemManagerToUpdate.System = additionalContact.System; systemManagerToUpdate.Fax = additionalContact.Fax; systemManagerToUpdate.Salutation = additionalContact.Salutation; systemManagerToUpdate.Version = additionalContact.Version + 1; systemManagerToUpdate.Role = additionalContact.Role; systemManagerToUpdate.NotificationSubscriber = additionalContact.NotificationSubscriber; systemManagerToUpdate.Active = additionalContact.Active; _db.SaveChanges(); _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, systemManagerBeforeUpdate, DtoHelper.CreateAdditionalContactDto(systemManagerToUpdate)); return(HttpStatusCode.OK); } else { _mongoMongoLogger.ConcurrenyServerLog <object, object>(HttpContext.Current.User, additionalContact); return(HttpStatusCode.Conflict); } } catch (Exception ex) { _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, additionalContact); return(HttpStatusCode.InternalServerError); } }
public long Update_AdditionalContacts(SMSBE.AdditionalContactsBE _objAddiBE) { try { AdditionalContact objAdditionalContact = _objSmsEntity.AdditionalContacts.Where(x => x.AdditionalContId == _objAddiBE.AdditionalContId).FirstOrDefault(); objAdditionalContact.ContactName = _objAddiBE.ContactName; objAdditionalContact.ContactNo = _objAddiBE.ContactNo; objAdditionalContact.LastModifiedBy = Convert.ToInt32(_objAddiBE.LastModifiedBy); objAdditionalContact.LastModifiedOn = DateTime.Now; _objSmsEntity.SaveChanges(); return(objAdditionalContact.AdditionalContId); } catch (Exception ex) { return(0); } }
public static object SetFields(List <string> fieldNames, List <object> fieldValues, object obj, ref string err) { err = ""; for (int i = 0; i < fieldNames.Count; i++) { if (fieldNames[i] != null) { PropertyInfo _propertyInfo = obj.GetType().GetProperty(fieldNames[i]); if (_propertyInfo == null) { if (fieldNames[i] == "Custom") { ((Abstract)obj).AddDataEx("ID", fieldValues[i].ToString()); } else { err = "Property with names " + fieldNames[i] + " does not exists in " + obj.GetType().ToString(); return(null); } } else { if (fieldNames[i] == "AdditionalContactRef") { if (((Vendor)obj).AdditionalContactRef == null) { ((Vendor)obj).AdditionalContactRef = new List <AdditionalContact>(); AdditionalContact adicional = new AdditionalContact(); adicional.ContactName = "Main Phone"; adicional.ContactValue = fieldValues[i].ToString(); ((Vendor)obj).AdditionalContactRef.Add(adicional); } } else { _propertyInfo.SetValue(obj, fieldValues[i], null); } } } } return(obj); }
public static AdditionalContactDto CreateAdditionalContactDto(AdditionalContact additionalContact) { var additionalContactDto = new AdditionalContactDto() { Id = additionalContact.Id, Name = additionalContact.Name, Email = additionalContact.Email, System = additionalContact.System, Salutation = additionalContact.Salutation, Telephone = additionalContact.Telephone, Fax = additionalContact.Fax, Role = additionalContact.Role, TrustUsername = additionalContact.TrustUsername, Active = additionalContact.Active, NotificationSubscriber = additionalContact.NotificationSubscriber, Version = additionalContact.Version }; return(additionalContactDto); }
/// <summary> /// Adds an additional contact to the database. /// </summary> public TestDatabaseBuilder AddAdditionalContact( string userName, string lastName, string firstName, string emailAddress) { var user = _buildContext.Users .SingleOrDefault(u => u.UserName == userName); var additionalContact = new AdditionalContact() { FirstName = firstName, LastName = lastName, EmailAddress = emailAddress, UserId = user.Id }; _buildContext.AdditionalContacts.Add(additionalContact); _buildContext.SaveChanges(); return(this); }
public long Insert_AdditionalContacts(SMSBE.AdditionalContactsBE _objAddiBE) { try { AdditionalContact objAdditionalContact = new AdditionalContact(); objAdditionalContact.ContactName = _objAddiBE.ContactName; objAdditionalContact.ContactNo = _objAddiBE.ContactNo; objAdditionalContact.AddedBy = _objAddiBE.AddedBy; objAdditionalContact.AddedOn = DateTime.Now; objAdditionalContact.LastModifiedBy = null; objAdditionalContact.LastModifiedOn = null; _objSmsEntity.AddToAdditionalContacts(objAdditionalContact); _objSmsEntity.SaveChanges(); return(objAdditionalContact.AdditionalContId); } catch (Exception ex) { return(0); } }
public static string GetFieldsToCsv(List <ProcesoParametros> parametros, string keyExternalValue, object obj, ref string err) { try { err = ""; List <String> fieldValues = new List <string>(); for (int i = 0; i < parametros.Count; i++) { if (!parametros[i].isKey) { if (parametros[i].Type == null) { PropertyInfo[] ifnoo = obj.GetType().GetProperties(); PropertyInfo _propertyInfo = obj.GetType().GetProperty(parametros[i].fieldName); if (_propertyInfo == null) { err = "Property with names " + parametros[i].fieldName + " does not exists in " + obj.GetType().ToString() + Environment.NewLine; return(null); } object objectValue = _propertyInfo.GetValue(obj, null); Abstract ObjectQuickbook = objectValue as Abstract; if (ObjectQuickbook != null) { fieldValues.Add(ObjectQuickbook.ListID); } else { fieldValues.Add(Convert.ToString(objectValue).Replace("\"", "\"\"")); } } else { string[] field = parametros[i].Type.ToString().Split('/'); string fieldPropertyCustom = field[0]; //custom string fieldPropertyName = field[1]; //ID if (fieldPropertyCustom == "Custom") { Abstract newValueObject = obj as Abstract; string value = newValueObject.getDataExValue(fieldPropertyName); if (value != null) { fieldValues.Add(value.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } else { if (fieldPropertyCustom == "AdditionalContactRef") { if (((Vendor)obj).AdditionalContactRef == null) { fieldValues.Add(""); } else { AdditionalContact newValue = ((Vendor)obj).AdditionalContactRef.Find(d => d.ContactName == "Main Phone"); if (newValue != null) { fieldValues.Add(newValue.ContactValue.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } } else { ////si es otro dato compuesto obtener el tipo string value = HelperTask.getObjectValue(parametros[i].fieldName, fieldPropertyCustom, obj, fieldPropertyName, ref err); if (value != null) { fieldValues.Add(value.Replace("\"", "\"\"")); } else { fieldValues.Add(""); } } } } } else { if (parametros[i].Type == "Configuration") { fieldValues.Add(Config.CompaniaDB); } else { if (keyExternalValue != string.Empty) { fieldValues.Add(keyExternalValue); } else { fieldValues.Add(""); } } } } string fila = "\"" + String.Join("\",\"", fieldValues.ToArray()) + "\""; //fila="\" return(fila); } catch (Exception ex) { err = ex.Message + Environment.NewLine; return(string.Empty); } }
/// <summary> /// Allows to find additional contact by it's content. /// Returns null if it does not exists. /// </summary> /// <param name="contact"></param> /// <param name="context"></param> /// <returns></returns> public static AdditionalContact FindAdditionalContact(AdditionalContact contact, AppDbContext context) { return(context.AdditionalContacts.Where(a => a.Type == contact.Type) .Where(a => a.Data == contact.Data).SingleOrDefault()); }