private UserDB LogicToDB(User user) { var userDB = new UserDB(); if (user != null) { userDB.ID = user.ID; userDB.Username = user.Username; userDB.Email = user.Email; userDB.Password = user.Password; userDB.Salt = user.Salt; userDB.FirstName = user.FirstName; userDB.LastName = user.LastName; userDB.Description = user.Description; if (user.Location != null) { userDB.Latitude = (decimal)user.Location.Latitude; userDB.Longitude = (decimal)user.Location.Longitude; } userDB.ProfilePicture = user.ProfilePicture; if (user.Skills != null) { foreach (var skillDB in user.Skills) { userDB.Skills.Add(skillController.LogicToDB(skillDB)); } } return(userDB); } return(null); }
public void Delete(User user) { var userDB = new UserDB(); userDB.ID = user.ID; userDB.Skills.Add(LogicToDB(user.Skills[0])); skillsAccess.Delete(userDB); }
private User DBToLogic(UserDB userDB) { var user = new User(); if (userDB != null) { user.ID = userDB.ID; user.Username = userDB.Username; user.Email = userDB.Email; var saltedPassword = StringCipher.Decrypt(userDB.Password, "hello"); user.Password = saltedPassword.Substring(0, saltedPassword.Length - userDB.Salt.Length); user.Salt = userDB.Salt; user.FirstName = userDB.FirstName; user.LastName = userDB.LastName; user.Description = userDB.Description; if (userDB.Latitude != null && userDB.Longitude != null) { user.Location = new LatLng((double)userDB.Latitude, (double)userDB.Longitude); } user.ProfilePicture = userDB.ProfilePicture; user.Skills = new List <Skill>(); foreach (var skill in userDB.Skills) { user.Skills.Add(skillController.DBToLogic(skill)); } user.Applications = new List <Application>(); foreach (var application in userDB.Applications) { user.Applications.Add(applicationController.DBToLogic(application)); } user.Files = new List <File>(); foreach (var file in userDB.Files) { if (file.Deleted != null) { continue; } var fileLogic = new File(); fileLogic.Name = file.Name; fileLogic.ID = file.ID; user.Files.Add(fileLogic); } return(user); } return(null); }