public ActionResult Update(ContactAdress contactAdress) { if (ModelState.IsValid) { ContactAdress ContactAdress = db.ContactAdresses.Find(contactAdress.Id); if (contactAdress.ImageFile != null) { string imageName = DateTime.Now.ToString("ddMMyyyyHHmmssffff") + contactAdress.ImageFile.FileName; string imagePath = Path.Combine(Server.MapPath("~/Uploads/img"), imageName); string OldimagePath = Path.Combine(Server.MapPath("~/Uploads/img"), ContactAdress.Image); System.IO.File.Delete(OldimagePath); contactAdress.ImageFile.SaveAs(imagePath); ContactAdress.Image = imageName; } ContactAdress.Country = contactAdress.Country; ContactAdress.Street = contactAdress.Street; ContactAdress.CreatedDate = contactAdress.CreatedDate; db.Entry(ContactAdress).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contactAdress)); }
public async Task <bool> Add(ContactAdress adress, int contactId) { using (var ctx = new ContactBookDbContext()) { var entity = ctx.Contacts .IncludeFilter(x => x.Adresses) .Single(x => x.Id == contactId); if (entity == null) { return(false); } ctx.Adresses.Add(new ContactAdress { ContactId = contactId, Street = adress.Street, HouseNumber = adress.HouseNumber, City = adress.City, Type = adress.Type, lat = adress.lat, lng = adress.lng }); await ctx.SaveChangesAsync(); return(true); } }
public AdressResponse ConvertAdressFromRequest(ContactAdress adress) { return(new AdressResponse { Street = adress.Street, HouseNumber = adress.HouseNumber, City = adress.City, Type = adress.Type }); }
static public Contact GetContact() { var adress = new ContactAdress() { Street = "Brivibas iela", HouseNumber = "132", City = "Riga", Type = AdressType.Home }; var email1 = new ContactEmail() { Email = "*****@*****.**", Type = EmailType.Work }; var email2 = new ContactEmail() { Email = "*****@*****.**", Type = EmailType.Work }; var phone = new ContactPhone() { PhoneNumber = "23156758", Type = PhoneType.Work }; var phone2 = new ContactPhone() { PhoneNumber = "26784567", Type = PhoneType.MobilePhone }; var adresses = new List <ContactAdress>(); var emails = new List <ContactEmail>(); var phones = new List <ContactPhone>(); adresses.Add(adress); emails.Add(email1); emails.Add(email2); phones.Add(phone); phones.Add(phone2); var contact = new Contact() { Name = "John", LastName = "Woodhill", Company = "Latvijas balzams", Notes = "A guy I met in a pub", DateOfBirth = "12-8-1974", Adresses = adresses, Phones = phones, Emails = emails }; return(contact); }
public ActionResult Delete(int id) { ContactAdress contactAdress = db.ContactAdresses.Find(id); if (contactAdress == null) { return(HttpNotFound()); } db.ContactAdresses.Remove(contactAdress); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Update(int id) { if (Session["AdminId"] == null) { return(RedirectToAction("Index", "Login")); } ContactAdress contactAdress = db.ContactAdresses.Find(id); if (contactAdress == null) { return(HttpNotFound()); } return(View(contactAdress)); }
public async Task <IHttpActionResult> Add(ContactAdress adress, int contactId) { var adresses = new List <ContactAdress>(); adresses.Add(adress); if (!validation.ValidateAdress(adresses)) { return(Conflict()); } var result = await service.Add(adress, contactId); if (!result) { return(NotFound()); } return(Ok()); }
public ActionResult Create(ContactAdress contactAdress) { if (ModelState.IsValid) { string imageName = DateTime.Now.ToString("ddMMyyyyHHmmssffff") + contactAdress.ImageFile.FileName; string imagePath = Path.Combine(Server.MapPath("~/Uploads/img"), imageName); contactAdress.ImageFile.SaveAs(imagePath); contactAdress.Image = imageName; db.ContactAdresses.Add(contactAdress); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public async Task <IHttpActionResult> Update(ContactAdress adress) { var adresses = new List <ContactAdress>(); adresses.Add(adress); validation.ValidateAdress(adresses); if (!validation.ValidateAdress(adresses)) { return(Conflict()); } var result = await service.Update(adress, adress.ContactId, adress.Id); if (!result) { return(NotFound()); } else { return(Ok()); } }
public void ValidateAdress_ShouldNotValidateBadAdress() { var validation = new ValidationServices(); var adress = new ContactAdress() { Street = "Zemg", City = "", HouseNumber = "43" }; var adress1 = new ContactAdress(); var adress2 = new ContactAdress(); var adresses = new List <ContactAdress>(); adresses.Add(adress); adresses.Add(adress1); adresses.Add(adress2); var expected = validation.ValidateAdress(adresses); Assert.False(expected); }