public HttpResponseMessage CreateANewGroupWithFriends(GroupClassCustom l_grp) { var res_Var = Request.CreateResponse <int>(System.Net.HttpStatusCode.Created, 0); try { using (TransactionScope scope = new TransactionScope()) { using (var context_Var = new MlaDatabaseEntities1()) { int id1; id_Int = l_grp.userId; group_key grpkey = new group_key(); grpkey.groupNo = l_grp.groupId; grpkey.groupKey = l_grp.groupKey; grpkey.userId = l_grp; context_Var.group_key.Add(grpkey); context_Var.SaveChanges(); res_Var = Request.CreateResponse <int>(System.Net.HttpStatusCode.Created, l_grp.groupId); } scope.Complete(); return(res_Var); } } catch (Exception e) { res_Var = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error"); return(res_Var); } }
public HttpResponseMessage AddPublickey(int userId, string groupKeyDef, string publicKey, string privategroupKey) { try { using (TransactionScope scope = new TransactionScope()) { using (var ctx = new MlaDatabaseEntities1()) { var objreg = (from reg in ctx.registers where reg.userId == userId select reg).SingleOrDefault(); objreg.publicKey = publicKey; group grp = new group(); grp.groupName = "UserDef"; grp.groupType = 1; grp.userId = userId; ctx.groups.Add(grp); ctx.SaveChanges(); group_key grpKey = new group_key(); grpKey.userId = userId; grpKey.groupNo = grp.groupNo; grpKey.groupKey = groupKeyDef; ctx.group_key.Add(grpKey); ctx.SaveChanges(); grp = new group(); grp.groupName = "Private"; grp.groupType = 3; grp.userId = userId; ctx.groups.Add(grp); ctx.SaveChanges(); grpKey = new group_key(); grpKey.userId = userId; grpKey.groupNo = grp.groupNo; grpKey.groupKey = privategroupKey; ctx.group_key.Add(grpKey); ctx.SaveChanges(); } scope.Complete(); } var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.Accepted, "Success"); return(response); } catch (Exception e) { var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error"); return(response); } }
public HttpResponseMessage AddAsFriend(EncryptionForFriends listofFriends) { try { int flagint = -1; flagint = listofFriends.friendId; using (TransactionScope scope = new TransactionScope()) { using (var ctx = new MlaDatabaseEntities1()) { int fIdint = Convert.ToInt32(listofFriends.friendId); var groupIdfromVar = ctx.groups.Where(x => x.userId == listofFriends.userId && x.groupType == 1).Select(x => x.groupNo).ToList(); int grpfromint = groupIdfromVar[0]; friendsTable fobj = new friendsTable(); fobj.user_id = listofFriends.userId; fobj.friend_id = fIdint; fobj.Isaccepted = false; fobj.groupNo = grpfromint; ctx.friendsTables.Add(fobj); group_key grk1 = new group_key(); grk1.groupNo = grpfromint; grk1.groupKey = listofFriends.groupKey; grk1.userId = fIdint; ctx.group_key.Add(grk1); ctx.SaveChanges(); } scope.Complete(); } var response = Request.CreateResponse <int>(System.Net.HttpStatusCode.Created, flagint); return(response); } catch (Exception e) { var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error"); return(response); } }
public HttpResponseMessage AcceptFriendRequest(int userId, int friendId, string groupkey, string groupId) { try { using (TransactionScope scope = new TransactionScope()) { using (var ctx = new MlaDatabaseEntities1()) { int groupIDint = Convert.ToInt32(groupId); friendsTable fobj = new friendsTable(); fobj.user_id = userId; fobj.friend_id = friendId; fobj.Isaccepted = false; fobj.groupNo = groupIDint; ctx.friendsTables.Add(fobj); ctx.SaveChanges(); var lstfrndVar = (from ft in ctx.friendsTables where ft.user_id == friendId && ft.friend_id == userId select ft).Union(from std in ctx.friendsTables where std.friend_id == friendId && std.user_id == userId select std).ToList(); lstfrndVar.ForEach(c => c.Isaccepted = true); group_key gkobj = new group_key(); gkobj.userId = friendId; gkobj.groupNo = Convert.ToInt32(groupId); gkobj.groupKey = groupkey; var query = ctx.group_key.Add(gkobj); ctx.SaveChanges(); } scope.Complete(); } var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.Created, "Success"); return(response); } catch (Exception e) { var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error"); return(response); } }
public HttpResponseMessage CreateANewGroup(GroupClassCustom listOfGroup) { try { using (TransactionScope scope = new TransactionScope()) { using (var context_Var = new MlaDatabaseEntities1()) { int id1; id1 = listOfGroup.OwnerId; group grpobj = new group(); grpobj.userId = id1; grpobj.groupType = 2; grpobj.groupName = listOfGroup.groupName; context_Var.groups.Add(grpobj); context_Var.SaveChanges(); group_key grpkey = new group_key(); grpkey.groupNo = grpobj.groupNo; grpkey.groupKey = listOfGroup.groupKey; grpkey.userId = id1; context_Var.group_key.Add(grpkey); context_Var.SaveChanges(); res_Var = Request.CreateResponse <int>(System.Net.HttpStatusCode.Created, grpobj.groupNo); } scope.Complete(); return(res_Var); } } catch (Exception e) { res_Var = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error"); return(res_Var); } }