public bool EditClient(ViewModel.clientView client) { if (client.clientName != string.Empty && client.clientId > 0) { var exist = n.Client.FirstOrDefault(c => c.name == client.clientName && c.ID != client.clientId); if (exist == null) { var editclint = n.Client.FirstOrDefault(c => c.ID == client.clientId); editclint.name = client.clientName; editclint.birthDate = client.birthdate != string.Empty ? DateTime.Parse(client.birthdate) : editclint.birthDate; editclint.age = client.age > 0? client.age : editclint.age; editclint.departmentId = client.departmentId; editclint.jobId = client.job; editclint.mail = client.mail; editclint.photo = client.photo; if (client.password != string.Empty) { editclint.password = client.password; } n.SaveChanges(); int clientId = client.clientId; deletePhone(clientId); deleteAddress(clientId); for (int i = 0; i < client.clientAddress.Count; i++) { client.clientAddress[i].clientId = client.clientId; addAddress(client.clientAddress[i]); } for (int i = 0; i < client.clientPhone.Count; i++) { client.clientPhone[i].clientId = client.clientId; addPhone(client.clientPhone[i]); } n.SaveChanges(); return(true); } return(false); } else { return(false); } }
public int AddClient(ViewModel.clientView client) { if (client.clientName != null && client.age > 0 && client.departmentId > 0 && client.job > 0) { var exist = n.Client.FirstOrDefault(c => c.name == client.clientName); if (exist == null) { noteData.Model.clients newclient = new noteData.Model.clients(); newclient.name = client.clientName; newclient.age = client.age; newclient.birthDate = DateTime.Parse(client.birthdate); newclient.departmentId = client.departmentId; newclient.jobId = client.job; newclient.mail = client.mail; newclient.photo = client.photo; newclient.password = client.password; n.Client.Add(newclient); n.SaveChanges(); int clientId = newclient.ID; for (int i = 0; i < client.clientAddress.Count; i++) { client.clientAddress[i].clientId = clientId; addAddress(client.clientAddress[i]); } for (int i = 0; i < client.clientPhone.Count; i++) { client.clientPhone[i].clientId = clientId; addPhone(client.clientPhone[i]); } return(clientId); } return(0); } else { return(0); } }