public string AddNewRecord(string title, string userName, string pass, string notes, string url, string token) { string res = string.Empty; using (var db = new MyPassWordsContext()) { try { Users user = db.Users.FirstOrDefault(u => u.Token == token); if (user != null) { Records rec = new Records() { Title = title, UserName = userName, PassWord = pass, Notes = notes, URL = url, RInsertDT = DateTime.Now }; db.Records.Add(rec); db.RecordForUser.Add( new RecordForUser() { Record = rec, User = user, RFUInsertDT = DateTime.Now }); db.SaveChanges(); res = rec.RID.ToString(); } } catch (Exception) { } } return(serializer.Serialize(res)); }
public string EditRecord(string title, string userName, string pass, string notes, string url, string token, string rec_Id) { try { int recId = int.Parse(rec_Id); using (var db = new MyPassWordsContext()) { Users user = db.Users.FirstOrDefault(u => u.Token == token); if (user == null) { return(serializer.Serialize("tokenError")); } RecordForUser checkPermissions = db.RecordForUser.FirstOrDefault(rfu => rfu.User.UID == user.UID && rfu.Record.RID == recId); if (checkPermissions == null) { return(serializer.Serialize("PermissionsDenied")); } Records recUpdate = db.Records.FirstOrDefault(r => r.RID == recId); if (recUpdate == null) { return(serializer.Serialize("RecordNotFound")); } recUpdate.Title = title; recUpdate.UserName = userName; recUpdate.PassWord = pass; recUpdate.Notes = notes; recUpdate.URL = url; db.SaveChanges(); return(serializer.Serialize("Success")); } } catch (Exception ex) { return(serializer.Serialize(ex.Message)); } }