public List <Note> GetAllNotes(int userId, DateTime?fromDate, DateTime?toDate) { try { using (var db = new NotesAppEntities()) { List <Note> notes; if (db.Users.Where(s => s.UserId == userId).FirstOrDefault().UserType == UserTypeEnum.User.ToString()) { notes = db.Notes.Where(s => s.UserId == userId).ToList(); } else { notes = db.Notes.Include("User").ToList(); } if (fromDate != null && toDate == null) { notes = notes.Where(s => s.CreatedUTC.Value.Date >= fromDate.Value.Date).ToList(); } else if (fromDate != null && toDate != null) { notes = notes.Where(s => s.CreatedUTC.Value.Date >= fromDate.Value.Date && s.CreatedUTC.Value.Date <= toDate.Value.Date).ToList(); } return(notes.OrderByDescending(s => s.CreatedUTC).ToList()); } } catch (Exception ex) { throw ex; } }
public bool AddNote(Note note, string ipAddress) { try { using (var db = new NotesAppEntities()) { db.Notes.Add(note); var result = db.Users.FirstOrDefault(s => s.UserId == note.UserId); result.IpAddress = ipAddress; db.AuthenticationLogs.Add( new AuthenticationLog { CreatedUTC = DateTime.UtcNow, UserId = note.UserId, LogType = LogTypeEnum.AddedNote.ToString() }); db.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public bool CheckValidForTransaction(int UserId, string UserIp) { try { using (var db = new NotesAppEntities()) { var CheckForMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["CheckForMinutes"]); var MaxLogCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxLogCount"]); var transactions = db.AuthenticationLogs.Where(s => s.User.IpAddress == UserIp && s.UserId == UserId).ToList(); var CountInOneMin = transactions.Where(s => s.CreatedUTC >= DateTime.UtcNow.AddMinutes(-CheckForMinutes)).ToList().Count; if (CountInOneMin > MaxLogCount) { db.BLockedIps.Add(new BLockedIp { IpAddress = UserIp, UserId = UserId, CreatedUTC = DateTime.UtcNow }); db.SaveChanges(); return(false); } else { return(true); } } } catch (Exception ex) { throw ex; } }
public User Login(LoginViewModel login, string ipAddress) { try { using (var db = new NotesAppEntities()) { var result = db.Users.FirstOrDefault(s => s.Email == login.Email && s.Password == login.Password); result.IpAddress = ipAddress; db.AuthenticationLogs.Add( new AuthenticationLog { CreatedUTC = DateTime.UtcNow, UserId = result.UserId, LogType = LogTypeEnum.Login.ToString() }); db.SaveChanges(); if (result != null) { return(result); } else { return(null); } } } catch (Exception ex) { throw ex; } }
public List <BLockedIp> GetBlockedIpList() { try { using (var db = new NotesAppEntities()) { return(db.BLockedIps.Include("User").OrderByDescending(s => s.CreatedUTC).ToList()); } } catch (Exception ex) { throw ex; } }
public bool Register(User user) { try { using (var db = new NotesAppEntities()) { db.Users.Add(user); db.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public HttpResponseMessage ProcessImageOCR(ImageData data) { try { HttpResponseMessage httpResponseMessage = new HttpResponseMessage(); using (var db = new NotesAppEntities()) { if (db.Images.Where(s => s.ImageBase64String == data.base64String).Any()) { var imagedata = db.Images.Where(s => s.ImageBase64String == data.base64String).FirstOrDefault(); if (imagedata != null) { string plainText = imagedata.OCRText; return(Extensions.GetTextFile(plainText)); } } if (!string.IsNullOrEmpty(data.base64String)) { var ImagePath = Extensions.LoadImage(data.base64String); if (!string.IsNullOrEmpty(ImagePath)) { var ext = Path.GetExtension(ImagePath); if (ext == ".jpg" || ext == ".jpeg") { using (var api = OcrApi.Create()) { api.Init(Languages.English, HttpContext.Current.Server.MapPath("~")); string plainText = api.GetTextFromImage(ImagePath); db.Images.Add(new Image { ImageBase64String = data.base64String, OCRText = plainText, CreatedUTC = DateTime.UtcNow }); db.SaveChanges(); return(Extensions.GetTextFile(plainText)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please give path for jpg or jpeg images only.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please give path for jpg or jpeg images only.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Please provide jpg image path to process ocr.")); } } } catch (Exception ex) { //throw ex; return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }