public void Delete(Contact model) { if (!User.Identity.IsAuthenticated) { Response.End(); } var id = model.ContactId; var contact = contactrepo.GetContactById(id); try { contactrepo.Delete(contact); contactrepo.Save();//persist change //make sure that client side knows we don't have errors var newmodel = helper.ToDictModel(contact); newmodel.Add("isError", false); Response.Write(serializer.Serialize(newmodel)); Response.End(); } catch (Exception ex) { var dictmodel = helper.ToDictModel(contact); dictmodel.Add("isError", ex.Message); Response.Write(serializer.Serialize(dictmodel)); Response.End(); } }
//get a contacts relationship name public string[] getRelationship(Contact contact) { var query = from rel in dbconn.Relationships where rel.RelationshipId == contact.RelationshipId select rel.Type; return query.ToArray(); }
//returns the right image for the contact public string filterContactImage(Contact contact) { string imageurl = contact.ImageUrl; if(string.IsNullOrEmpty(imageurl)){ imageurl = "/app/img/placeholder.png"; } return imageurl; }
private void detach_Contacts(Contact entity) { this.SendPropertyChanging(); entity.Relationship = null; }
partial void DeleteContact(Contact instance);
partial void UpdateContact(Contact instance);
partial void InsertContact(Contact instance);
//post action to upload file from the user public void Upload(Contact model, HttpPostedFileBase file) { Contact contact = contactrepo.GetContactById(model.ContactId); if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/app/uploads"), fileName); file.SaveAs(path); contact.ImageUrl = "/app/uploads/" + fileName; contactrepo.Save(); } Response.Write(serializer.Serialize(helper.ToDictModel(contact))); Response.End(); }
public void Save(Contact model) { if (!User.Identity.IsAuthenticated) { Response.End(); } var id = model.ContactId; bool isUpdate = false; Contact contact = new Contact(); if(id > 0){ isUpdate = true; contact = contactrepo.GetContactById(id); } try { contact.FirstName = model.FirstName; contact.LastName = model.LastName; contact.Phone = model.Phone; contact.Country = model.Country; contact.Address = model.Address; contact.RelationshipId = model.RelationshipId; if (!isUpdate) { contactrepo.Add(contact); } contactrepo.Save(); //make sure that client side knows we don't have errors var newmodel = helper.ToDictModel(model); newmodel.Add("isError", false); Response.Write(serializer.Serialize(newmodel)); Response.End(); } catch(Exception ex) { IEnumerable<Error> errors = contact.GetErrors(); var errormodel = helper.ToDictModel(model); string errorstring = ""; foreach (Error error in errors) { errorstring += "<p>" + error.ErrorMessage + "</p>"; } if (string.IsNullOrEmpty(errorstring)) { errorstring = ex.Message; } errormodel.Add("isError", errorstring); Response.Write(serializer.Serialize(errormodel)); Response.End(); } }
public void Delete(Contact contact) { dbconn.Contacts.DeleteOnSubmit(contact); }
public void Add(Contact contact) { dbconn.Contacts.InsertOnSubmit(contact); }