public Boolean upload([FromBody] FileUploadModel file) { if (!isValidateApiUser(file.token)) { return(false); } try { db.Files.Add(file.file); IQueryable <UserPlanModel> up = db.UserPlans.Where(u => u.username == file.file.username).OrderBy(u => u.priority); int flag = 0; foreach (UserPlanModel u in up) { if (u.storageRemaining >= file.file.size) { u.storageRemaining -= file.file.size; db.Entry(u).State = EntityState.Modified; flag = 1; break; } } if (flag == 0) { return(false); } db.SaveChanges(); return(true); }catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public IHttpActionResult PutTokenUsersModel(string id, TokenUsersModel tokenUsersModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tokenUsersModel.token) { return(BadRequest()); } db.Entry(tokenUsersModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TokenUsersModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static void Index() { RSS_DB_EF db = new RSS_DB_EF(); List <UserPlanModel> users = db.UserPlans.Where(p => p.expiryTime.Month == DateTime.Now.Month && p.expiryTime.Day == DateTime.Now.Day).ToList(); if (users != null) { db.UserPlans.RemoveRange(users); db.SaveChanges(); } List <FileModel> files = db.Files.Where(f => (f.sharingDuration.Month == DateTime.Now.Month && f.sharingDuration.Day == DateTime.Now.Day) || (f.fileDuration.Month == DateTime.Now.Month && f.fileDuration.Day == DateTime.Now.Day)).ToList(); if (files != null) { db.Files.RemoveRange(files); db.SaveChanges(); } }
public bool UpdatePass(string username, [FromBody] string password) { TokenUserModel user = db.Tokens.Find(username); if (user == null) { return(false); } user.password = password; db.Entry <TokenUserModel>(user).State = EntityState.Modified; try { db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public String upload([FromBody] FileModel file) { int flag = 0; while (flag == 0) { file.token = Guid.NewGuid().ToString(); var files = db.Files.ToList(); flag = 1; foreach (FileModel f in files) { if (file.token == f.token) { flag = 0; break; } } } db.Files.Add(file); IQueryable <UserPlanModel> up = db.UserPlans.Where(u => u.username == file.username).OrderBy(u => u.priority); flag = 0; foreach (UserPlanModel u in up) { if (u.storageRemaining >= file.size) { u.storageRemaining -= file.size; db.Entry <UserPlanModel>(u).State = EntityState.Modified; flag = 1; break; } } if (flag == 0) { return(null); } db.SaveChanges(); return(file.token); }
public Boolean register([FromBody] UserRegistrationModel user) { if (!isValidateApiUser(user.token)) { return(false); } try { if (db.Users.Find(user.user.username) != null) { return(false); } user.user.isVerified = false; user.user.isActive = false; db.Users.Add(user.user); VerifyAccountModel va = new VerifyAccountModel(); va.username = user.user.username; int flag = 0; while (flag == 0) { va.token = Guid.NewGuid().ToString(); foreach (VerifyAccountModel v in db.VerifyAccounts) { if (va.token == v.token) { flag = 0; continue; } } flag = 1; } va.gen_time = DateTime.Now; db.VerifyAccounts.Add(va); db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public string register([FromBody] UserModel user) { try { if (db.Users.Find(user.username) != null) { return("Username Already is in Use.Please try with different Username"); } user.isVerified = true; user.isActive = true; db.Users.Add(user); VerifyAccountModel va = new VerifyAccountModel(); va.username = user.username; int flag = 0; while (flag == 0) { va.token = Guid.NewGuid().ToString(); foreach (VerifyAccountModel v in db.VerifyAccounts) { if (va.token == v.token) { flag = 0; continue; } } flag = 1; } va.gen_time = DateTime.Now; db.VerifyAccounts.Add(va); db.SaveChanges(); //sending token return("Registered Successfully"); } catch (Exception e) { Console.WriteLine(e.Message); return("Something Went Wrong.Please try again later."); } }
public bool addPlan(AddPlanModel user) { if (!isValidateApiUser(user.token)) { return(false); } using (db) { try { PlanModel p = db.Plans.Find(user.id); if (p == null) { return(false); } UserPlanModel up = new UserPlanModel(); int max = 0; foreach (UserPlanModel t in db.UserPlans.Where(u => u.username == user.username)) { if (t != null && t.priority > max) { max = t.priority; } } up.id = user.id; up.username = user.username; up.expiryTime = DateTime.Now.AddDays(p.validity); up.storageRemaining = p.storageBenefit; up.subTime = DateTime.Now; up.priority = max + 1; db.UserPlans.Add(up); db.SaveChanges(); return(true); }catch (Exception e) { Console.WriteLine(e.Message); return(false); } } }
public string createGroup(GroupModel group) { UserModel user = db.Users.Find(group.owner); if (user == null) { return(null); } group.id = group.owner + group.groupName; group.reqPending = 0; db.Groups.Add(group); GroupMemberModel gm = new GroupMemberModel(); gm.id = group.id; gm.reqStatus = true; gm.username = group.owner; db.GroupMembers.Add(gm); db.SaveChanges(); return(group.id); }