public ActionResult Edit() { UnitOfWork unit = new UnitOfWork(); PhonesService phoneService = new PhonesService(unit); PhoneEditVM model = new PhoneEditVM(); TryUpdateModel(model); Phone p; if (!ModelState.IsValid) { return(View(model)); } if (model.ID != 0) { p = phoneService.GetByID(model.ID); } else { p = new Phone(); } Mapper.Map(model, p); phoneService.Save(p); return(this.RedirectToAction(c => c.List(), new { contactID = model.ContactID })); }
public void EditAsync_ReturnsCorrectNumberOfModifiedEntries() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone = new Phone() { PhoneNumber = "0897248721" }; EditPhoneServiceModel model = new EditPhoneServiceModel { Id = 1, PhoneNumber = "0897248722", }; var phonesService = new PhonesService(dbContext); dbContext.Phones.Add(phone); dbContext.SaveChanges(); var result = phonesService.EditAsync(model); Assert.Equal(1, result.Result); } }
public ActionResult Edit(int?id) { PhonesService phonesService = new PhonesService(); PhonesEditVM model = new PhonesEditVM(); TryUpdateModel(model); Phone phone; if (!id.HasValue) { phone = new Phone(); } else { phone = phonesService.GetByID(id.Value); if (phone == null) { if (phonesService.GetContact(model.ContactID) == null) { return(this.RedirectToAction <ContactsController>(c => c.List())); } return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); } model.ContactID = phone.ContactID; } Mapper.Map(phone, model); return(View(model)); }
public void All_ReturnsCorrectCollection() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone1 = new Phone() { PhoneNumber = "0897248721" }; Phone phone2 = new Phone() { PhoneNumber = "0897248722" }; dbContext.Phones.Add(phone1); dbContext.Phones.Add(phone2); dbContext.SaveChanges(); var phonesService = new PhonesService(dbContext); var phones = phonesService.All(); Assert.Collection(phones, item => Assert.Contains("0897248721", phone1.PhoneNumber), item => Assert.Contains("0897248722", phone2.PhoneNumber)); } }
private void BtnDelete_Click(object sender, EventArgs e) { ListView listViewPhones = FindViewById <ListView>(Resource.Id.listViewPhones); Button btnDelete = FindViewById <Button>(Resource.Id.btnDelete); PhonesService phonesService = new PhonesService(); var confirm = new AlertDialog.Builder(this); confirm.SetMessage("Are you sure you want to delete " + selectedPhones.Count + " phones?"); confirm.SetPositiveButton("Yes", delegate { for (int i = 0; i < selectedPhones.Count; i++) { phonesService.Delete(selectedPhones[i]); MainActivity.SelectedContact.Phones.Remove(selectedPhones[i]); } var okMessage = new AlertDialog.Builder(this); okMessage.SetMessage(selectedPhones.Count + " phones deleted!"); okMessage.SetPositiveButton("Okay", delegate { }); okMessage.Show(); listViewPhones.Adapter = RefreshAdapter();; selectedPhones.Clear(); btnDelete.Enabled = false; Recreate(); }); confirm.SetNegativeButton("No", delegate { Recreate(); }); confirm.Show(); }
public void Exists_ReturnsFalse() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { var phonesService = new PhonesService(dbContext); var result = phonesService.Exists(1); Assert.False(result); } }
public ActionResult Delete(int?id) { if (!id.HasValue) { return(this.RedirectToAction <ContactsController>(c => c.List())); } PhonesService phonesService = new PhonesService(); int contactID = phonesService.GetContactID(id.Value); phonesService.Delete(id.Value); return(this.RedirectToAction(c => c.List(), new { ContactID = contactID })); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ViewContact); TextView lblContactName = FindViewById <TextView>(Resource.Id.textViewContactName); TextView lblContactMail = FindViewById <TextView>(Resource.Id.textViewEmail); Button btnDelete = FindViewById <Button>(Resource.Id.btnDelete); Button btnEditContact = FindViewById <Button>(Resource.Id.btnEditContact); Button btnAddPhone = FindViewById <Button>(Resource.Id.btnAddPhone); ImageView contactImageView = FindViewById <ImageView>(Resource.Id.ContactImageView); if (MainActivity.SelectedContact.ImageURI != null) { Android.Net.Uri imageUri = Android.Net.Uri.Parse(MainActivity.SelectedContact.ImageURI); contactImageView.SetImageURI(imageUri); } ListView listViewPhones = FindViewById <ListView>(Resource.Id.listViewPhones); listViewPhones.ChoiceMode = ChoiceMode.Multiple; ArrayAdapter phoneDetails = RefreshAdapter(); listViewPhones.Adapter = phoneDetails; lblContactName.Text = MainActivity.SelectedContact.FirstName + " " + MainActivity.SelectedContact.LastName; lblContactMail.Text = "Email: " + MainActivity.SelectedContact.Email; PhonesService phonesService = new PhonesService(); MainActivity.SelectedContact.Phones = phonesService.GetPhonesByContactID(MainActivity.SelectedContact.ID).ToList(); //launches the EditContact activity btnEditContact.Click += BtnEditContact_Click; //Launches the AddPhone activity btnAddPhone.Click += BtnAddPhone_Click; //launches an activity to edit phones listViewPhones.ItemLongClick += ListViewPhones_ItemLongClick; //Selects items to be deleted listViewPhones.ItemClick += ListViewPhones_ItemClick; //creates an activity to delete phones btnDelete.Click += BtnDelete_Click; //launches an intent to select an image contactImageView.Click += ContactImageView_Click; //launches an intent to send an email lblContactMail.Click += LblContactMail_Click; }
public ActionResult Delete(int?id) { PhonesService phoneService = new PhonesService(); if (!id.HasValue) { return(this.RedirectToAction(c => c.List())); } else { phoneService.Delete(id.Value); } return(this.RedirectToAction(c => c.List())); }
public void CreateAsync_ReturnsCorrectPhoneId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { CreatePhoneServiceModel phone = new CreatePhoneServiceModel { PhoneNumber = "0897248721", }; var phonesService = new PhonesService(dbContext); var result = phonesService.CreateAsync(phone); Assert.Equal(1, result.Result); } }
public ActionResult List() { PhonesService phonesService = new PhonesService(); PhonesListVM model = new PhonesListVM(); TryUpdateModel(model); if (!model.ContactID.HasValue || phonesService.GetContact(model.ContactID.Value) == null) { return(this.RedirectToAction <ContactsController>(c => c.List())); } model.Phones = phonesService.GetAll().Where(p => p.ContactID == model.ContactID.Value).ToList(); model.Contact = phonesService.GetContact(model.ContactID.Value); return(View(model)); }
public void IsPhoneContainedInOtherDepartments_ReturnsTrue() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Department department = new Department() { Name = "test", Email = "*****@*****.**" }; Department department2 = new Department() { Name = "test", Email = "*****@*****.**" }; dbContext.Departments.Add(department); dbContext.Departments.Add(department2); DepartmentPhone departmentPhone = new DepartmentPhone() { DepartmentId = 1, PhoneId = 1 }; DepartmentPhone departmentPhone2 = new DepartmentPhone() { DepartmentId = 2, PhoneId = 1 }; dbContext.DepartmentPhones.Add(departmentPhone); dbContext.DepartmentPhones.Add(departmentPhone2); Phone phone = new Phone() { PhoneNumber = "0897248721" }; phone.Departments.Add(departmentPhone); phone.Departments.Add(departmentPhone2); var phonesService = new PhonesService(dbContext); dbContext.Phones.Add(phone); dbContext.SaveChanges(); var result = phonesService.IsPhoneContainedInOtherDepartments(phone.PhoneNumber); Assert.True(result); } }
public void Count_ReturnsCorrectCount() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone = new Phone() { PhoneNumber = "0897248721", IsInternal = true }; dbContext.Phones.Add(phone); dbContext.SaveChanges(); var phonesService = new PhonesService(dbContext); int qualificationsCount = phonesService.Count(); Assert.Equal(1, qualificationsCount); } }
public void IsPhoneContainedInOtherDepartments_ReturnsFalse() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone = new Phone() { PhoneNumber = "0897248721", }; var phonesService = new PhonesService(dbContext); dbContext.Phones.Add(phone); dbContext.SaveChanges(); var result = phonesService.IsPhoneContainedInOtherDepartments(phone.PhoneNumber); Assert.False(result); } }
public void RemoveAsync_ReturnsTrue() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone = new Phone() { PhoneNumber = "0897248721" }; var phonesService = new PhonesService(dbContext); dbContext.Phones.Add(phone); dbContext.SaveChanges(); var result = phonesService.RemoveAsync(1); Assert.True(result.Result); } }
private void BtnCreatePhone_Click(object sender, EventArgs e) { Spinner phoneType = FindViewById <Spinner>(Resource.Id.spinnerPhoneType); EditText phoneNumber = FindViewById <EditText>(Resource.Id.editTextPhoneNumber); p.Type = phoneType.SelectedItem.ToString(); p.Number = phoneNumber.Text; p.ContactID = MainActivity.SelectedContact.ID; PhonesService phonesService = new PhonesService(); phonesService.Save(p); MainActivity.SelectedContact.Phones.Clear(); MainActivity.SelectedContact.Phones = phonesService.GetPhonesByContactID(MainActivity.SelectedContact.ID).ToList(); Intent intentResult = new Intent(this, typeof(ViewContactActivity)); SetResult(Result.Ok, intentResult); Finish(); }
public void GetById_ReturnsCorrectPhone() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Phone phone = new Phone() { PhoneNumber = "0897248721" }; dbContext.Phones.Add(phone); dbContext.SaveChanges(); var phonesService = new PhonesService(dbContext); var result = phonesService.GetById(1); Assert.Equal("0897248721", result.PhoneNumber); } }
public ActionResult Edit() { PhonesService phonesService = new PhonesService(); PhonesEditVM model = new PhonesEditVM(); TryUpdateModel(model); if (phonesService.GetContact(model.ContactID) == null) { return(this.RedirectToAction <ContactsController>(c => c.List())); } Phone phone; if (model.ID == 0) { phone = new Phone(); } else { phone = phonesService.GetByID(model.ID); if (phone == null) { return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); } } if (!ModelState.IsValid) { return(View(model)); } Mapper.Map(model, phone); phonesService.Save(phone); return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); }
public static void Main(string[] args) { using (HealthDbContext db = new HealthDbContext()) { //db.Database.EnsureDeleted(); //db.Database.EnsureCreated(); db.Database.Migrate(); //Seed seed = new Seed(); //seed.SeedDataBase(db); IBloodsService bloodsService = new BloodsService(db); IAddressesService addressesService = new AddressesService(db); IPhonesService phonesService = new PhonesService(db); IEmailsService emailsService = new EmailsService(db); IRelativesService relativesService = new RelativesService(db, addressesService, phonesService, emailsService); IDoctorsService doctorsService = new DoctorsService(db, addressesService, phonesService, emailsService); IPersonsService personsService = new PersonsService(db, addressesService, phonesService, emailsService, relativesService); IVaccinesService vaccinesService = new VaccinesService(db); IAllergiesService allergiesService = new AllergiesService(db); IChronicDiseasesService chronicDiseasesService = new ChronicDiseasesService(db); IPersonDiseasesService personVaccinesService = new PersonVaccinesService(db, vaccinesService); IPersonDiseasesService personAlleriesService = new PersonAllergiesService(db, allergiesService); IPersonDiseasesService personChronicDiseasesService = new PersonChronicDiseasesService(db, chronicDiseasesService); IMedicinesService medicinesService = new MedicinesService(db); IPrescriptionsService prescriptionsService = new PrescriptionsService(db, medicinesService); IReferralsService referralsService = new ReferralsService(db); ITreatmentsService treatmentsService = new TreatmentsService(db); IExaminationsService examinationsService = new ExaminationsService(db); IHospitalizationsService hospitalizationsService = new HospitalizationsService(db, examinationsService, treatmentsService); #region //examinationsService.Add(new ExaminationInputModel() //{ // Date = "21.09.2019", // Diagnosis = "very sick man", // DoctorId = "bedfa8a0-46d7-4369-8f85-fe3b1be57095", // PersonId = "9c591451-96e6-4dff-a225-32f092c7b56d", //}); //prescriptionsService.Add("565d1e5a-68df-45ab-8fea-e9d914fc891f"); //prescriptionsService.AddMedicine("7db87d46-6d71-4355-a482-95e2bf726465", // new MedicineInputModel() // { // Name = "Mesalazin Unipharm", // DaylyDoze = "250mg" // }); //examinationsService.AddPrescription("565d1e5a-68df-45ab-8fea-e9d914fc891f", "7db87d46-6d71-4355-a482-95e2bf726465"); //string referralId = referralsService.Add(new ReferralInputModel() // { // ExaminationId = "565d1e5a-68df-45ab-8fea-e9d914fc891f", // Specialty = "Cardiologist" // }); //examinationsService.AddReferral("565d1e5a-68df-45ab-8fea-e9d914fc891f", referralId); //hospitalizationsService.AddExamination("22a65132-1949-4e13-bbbc-35201429d0fb", "565d1e5a-68df-45ab-8fea-e9d914fc891f"); //hospitalizationsService.AddTreatment("22a65132-1949-4e13-bbbc-35201429d0fb", "44f6112f-542a-4eaf-a0b9-5685441f3937"); //hospitalizationsService.Add(new HospitalizationInputModel() //{ // EnterDate = "20.08.2019", // DischargeDate = "25.08.2019", // HospitalId = 1, // PersonId = "9c591451-96e6-4dff-a225-32f092c7b56d" //}); //hospitalizationsService.Add(new HospitalizationInputModel() //{ // EnterDate = "20.09.2019", // HospitalId = 1, // PersonId = "9c591451-96e6-4dff-a225-32f092c7b56d" //}); //treatmentsService.Add(new TreatmentInputModel() //{ // Description = "knee surgery...", // Date = "21.09.2019", // DoctorId = "bedfa8a0-46d7-4369-8f85-fe3b1be57095", // HospitalizationId = "22a65132-1949-4e13-bbbc-35201429d0fb" //}); //doctorsService.Add(new DoctorInputModel() //{ // FirstName = "Boiko", // LastName = "Penkov", // HospitalId = 1, // Specialty = "Cardiologist", // Address = new AddressInputModel() // { // Town = "Sofia", // Street = "ul. Alen Mak 1" // }, // Phone = new PhoneInputModel() // { // PhoneNumber = "0888989898" // }, // Email = new EmailAddressInputModel() // { // Email = "*****@*****.**" // }, //}); //personChronicDiseasesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Parkinson disease", // DiagnosedOn = "13.10.1973" // }); //personChronicDiseasesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Parkinson disease new", // DiagnosedOn = "13.10.1973" // }); //personAlleriesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Wheat[26]", // DiagnosedOn = "13.10.1973" // }); //personAlleriesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Wheat[26] (1)", // DiagnosedOn = "13.10.1973" // }); //personVaccinesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Strontium chloride", // DiagnosedOn = "13.10.1973" // }); //personVaccinesService.AddPersonDiseaseInfo("bedfa8a0-46d7-4369-8f85-fe3b1be57095", // "9c591451-96e6-4dff-a225-32f092c7b56d", new PersonDiseaseInfoInputModel() // { // Name = "Strontium chloride new", // DiagnosedOn = "13.10.1973" // }); //PersonInputModel personInputModel = new PersonInputModel() //{ // FirstName = "Kamen", // MiddleName = "Dimitrov", // LastName = "Pankov", // PersonalNumber = "7310136488", // BloodId = bloodsService.GetBloodId(BloodType.A, RhD.Negative), // HasHealthInsurance = true, // Address = new AddressInputModel() // { // Town = "Sofia", // Street = "Lerin 45" // } //}; //personsService.Add(personInputModel); //Person person = personsService.GetPerson("9c591451-96e6-4dff-a225-32f092c7b56d"); //personsService.AddPhone("9c591451-96e6-4dff-a225-32f092c7b56d", new PhoneInputModel() //{ // PhoneNumber = "0888086820" //}); //personsService.AddEmail("9c591451-96e6-4dff-a225-32f092c7b56d", new EmailAddressInputModel() //{ // Email = "*****@*****.**" //}); //personsService.AddRelative("9c591451-96e6-4dff-a225-32f092c7b56d", // new RelativeInputModel() // { // FirstName = "Desi", // MiddleName = "Svetlozarova", // LastName = "Velkovska", // Address = new AddressInputModel() // { // Town = "Sofia", // Street = "ul. Dobrudjanski krai 1" // }, // Phone = new PhoneInputModel() // { // PhoneNumber = "0888127876" // }, // Email = new EmailAddressInputModel() // { // Email = "*****@*****.**" // }, // RelativeType = "spouse" // }); #endregion } }