//验证 用户是否 阅读隐私政策记录(参数:openid) public BaseViewModel CheckReadLog(string openid) { BaseViewModel baseView = new BaseViewModel(); if (openid == "") { baseView.Message = "参数为空"; baseView.ResponseCode = 2; } else { try { //验证 用户是否 阅读隐私政策记录 ReadLog log = _readLogRepository.GetReadLog(openid); if (log != null) { baseView.Message = "我已阅读"; baseView.ResponseCode = 0; } else { baseView.Message = "我未阅读"; baseView.ResponseCode = 1; } } catch (Exception ex) { baseView.Message = "出现异常"; baseView.ResponseCode = 3; } } return(baseView); }
/// <summary> /// 添加阅读记录 /// </summary> /// <param name="rl"></param> /// <returns></returns> public int AddReadLog(ReadLog readlog) { string sqlstr = "INSERT INTO [dbo].[epub_readlog]([SiteID],[UserID],[BookID],[ReadType],[PageNumber],[IP],[SourceType]) " + " VALUES(@SiteID,@UserID,@BookID,@ReadType,@PageNumber,@IP,@SourceType)"; return(helper.ExecuteNonQueryFromDB <ReadLog>(sqlstr, ConnectionEnum.SqlServerLogConnection, readlog)); }
// Use this for initialization void Start() { dist = 8f; a = 0; incl = 30; Rdlog = GameObject.Find("Directional Light").GetComponent <Map>().rlog; }
public void IsFileLogOpen_ExceptionThrown() { // Arrange IReadLog readLog = new ReadLog(); // Act and assert exception Assert.Throws <>() }
public void IsFileLogOpen_True() { // Arrange IReadLog readLog = new ReadLog(); // Act // Assert }
public void IsFileLogOpen_False() { // Arrange IReadLog readLog = new ReadLog(); // Act var actualValue = readLog.IsFileLogOpen(); // Assert }
public bool AddLog(ReadLog newLog) { var logValidated = validateLog(newLog); if (logValidated) { dbContext.Add(newLog); dbContext.SaveChanges(); } return(logValidated); }
public bool UpdateLog(ReadLog log) { var logValidated = validateLog(log); if (logValidated) { dbContext.Update(log); dbContext.SaveChanges(); } return(logValidated); }
public void IsFileLogExists_AreEqualExistsOrNotExists() { // Arrange IReadLog readLog = new ReadLog(); var pathProjectTests = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; var pathSolution = Directory.GetParent(pathProjectTests).Parent.FullName; var fullPathFileLog = pathSolution + "\\" + "Zin-Service.Service" + "\\Logs\\Log.txt"; var expectedValue = File.Exists(fullPathFileLog); // Act var actualValue = readLog.IsFileLogExists(); // Assert Assert.AreEqual(expectedValue, actualValue); }
public IActionResult Edit(Book bookReturned) { //If model is not valid return to inform the user if (!ModelState.IsValid) { return(View()); } //If book has valid id, update it, else create it. if (bookReturned.BookId > 0) { booksRepository.UpdateBook(bookReturned); return(RedirectToAction("Index", "Home")); } else { bookReturned.UserName = User.Identity.Name; switch (bookReturned.Status) { case BookStatus.ToRead: booksRepository.AddBook(bookReturned); return(RedirectToAction("Index", "Home")); case BookStatus.CurrentlyReading: booksRepository.AddBook(bookReturned); //Ask for initial log of book return(RedirectToAction("Create", "ReadLogs", new { id = bookReturned.BookId, bookName = bookReturned.Name })); case BookStatus.Read: //Create finish log for book var finishLog = new ReadLog() { Book = bookReturned, LogDate = DateTime.Today, PageNumber = bookReturned.NumberOfPages }; //Add log and save book bookReturned.ReadLogs.Add(finishLog); booksRepository.AddBook(bookReturned); return(RedirectToAction("Index", "Home")); default: return(RedirectToAction("Index", "Home")); } } }
public IActionResult FinishReading(int id) { var bookFinished = booksRepository.GetBookById(id); //Create finish log for book var finishLog = new ReadLog() { Book = bookFinished, LogDate = DateTime.Today, PageNumber = bookFinished.NumberOfPages, Note = "Finish Log." }; //Add log, save book and update status bookFinished.ReadLogs.Add(finishLog); bookFinished.Status = BookStatus.Read; booksRepository.UpdateBook(bookFinished); return(RedirectToAction("Index", "Home")); }
static void Main(string[] args) { IReadLog _ReadLog = new ReadLog(); ICorridaServices corridaServices = new CorridaServices(); string _pathLog = $@"{Directory.GetCurrentDirectory()}\\..\\..\\..\\..\\..\\LogCorrida.txt"; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("\r\n \r\n Seja bem vindo ao resultado da corrida \r\n \r\n"); var _arrayLog = _ReadLog.ReadResult(_pathLog); // Resumo da Prova corridaServices.ResultadoCorrida(_arrayLog); corridaServices.MelhorVoltaCorrida(); corridaServices.MelhorVoltaCadaPiloto(); corridaServices.VelocidadeMediaCadaPiloto(); }
public IActionResult Create([Bind("ReadLogId,PageNumber,LogDate,Note")] ReadLog readLog, int id, string bookName) { if (ModelState.IsValid) { readLog.BookId = id; var logCreated = readLogsRepository.AddLog(readLog); booksRepository.UpdateBookStatus(id); if (logCreated) { return(RedirectToAction("Detail", "Book", new { id })); } else { ModelState.AddModelError("log-validation", "There was an error validating the log. Check either the page number or the date."); } } ViewData["BookId"] = id; ViewData["BookName"] = bookName; return(View(readLog)); }
// Use this for initialization void Start() { GameObject damObject = new GameObject("Dam"); damObject.transform.parent = transform; dam = damObject.AddComponent <Dam>(); dam.tilePrefab = (GameObject)Resources.Load("Cube"); GameObject rlogObject = new GameObject("ReadLog"); rlogObject.transform.parent = transform; rlog = rlogObject.AddComponent <ReadLog>(); rlog.dam = dam; rlog.prefabs.Add((GameObject)Resources.Load("Robot")); rlog.prefabs.Add((GameObject)Resources.Load("Battery")); rlog.prefabs.Add((GameObject)Resources.Load("Linemate")); rlog.prefabs.Add((GameObject)Resources.Load("Deraumere")); rlog.prefabs.Add((GameObject)Resources.Load("Sibur")); rlog.prefabs.Add((GameObject)Resources.Load("Mendiane")); rlog.prefabs.Add((GameObject)Resources.Load("Phiras")); rlog.prefabs.Add((GameObject)Resources.Load("Thystame")); }
//获取用户阅读政策记录 public ReadLog GetReadLog(string openid) { ReadLog log = new ReadLog(); //查询条件 var predicate = WhereExtension.True <ReadLog>();//初始化where表达式 if (!String.IsNullOrEmpty(openid)) { predicate = predicate.And(p => p.openid.Contains(openid)); } var result = DbSet.Where(predicate).ToList(); if (result.Count != 0) { log = result.First(); } else { log = null; } return(log); }
public ActionResult Create(Contents contents) { if (ModelState.IsValid) { var c = Request.Files[0]; if (c != null && c.ContentLength > 0) { int lastSlashIndex = c.FileName.LastIndexOf("\\"); string fileName = c.FileName.Substring(lastSlashIndex + 1, c.FileName.Length - lastSlashIndex - 1); int lastDotIndex = fileName.LastIndexOf("."); string fileType = fileName.Substring(lastDotIndex + 1); string guid = Guid.NewGuid().ToString(); string realName = guid + "." + fileType; string savePath = Path.Combine(Server.MapPath("/Documents/"), realName); c.SaveAs(savePath); contents.Name = fileName.Substring(0, lastDotIndex); contents.Title = contents.Name; contents.RealName = realName; contents.Extension = fileType; contents.Size =c.ContentLength; contents.StatusId = 0; contents.MainBody =""; contents.CreaterId =(int)Session["CurrentEmp"]; contents.CreateTime = DateTime.Now; db.Contents.Add(contents); var readLog = new ReadLog { EmpId = (int)Session["CurrentEmp"], ContentId = contents.Id,ReadTime=DateTime.Now}; db.ReadLog.Add(readLog); db.SaveChanges(); return Redirect("Index/" + Request.QueryString["modelId"] + "?productId=" + Request.QueryString["productId"]); } } IEnumerable<Menus> modelMenus = db.Database.SqlQuery<Menus>(string.Format(_queryStr, 30)); ViewBag.ModelId = new SelectList(modelMenus, "Id", "Title", contents.ModelId); IEnumerable<Menus> productMenus = db.Database.SqlQuery<Menus>(string.Format(_queryStr, 8)); ViewBag.ProductId = new SelectList(productMenus, "Id", "Title",contents.ProductId); return View(contents); }
public IActionResult Edit(int id, [Bind("ReadLogId,PageNumber,LogDate,Note,BookId")] ReadLog readLog) { if (id != readLog.ReadLogId) { return(NotFound()); } if (ModelState.IsValid) { try { var logUpdated = readLogsRepository.UpdateLog(readLog); booksRepository.UpdateBookStatus(readLog.BookId); if (logUpdated) { return(RedirectToAction("Logs", "Book", new { id = readLog.BookId })); } else { ModelState.AddModelError("log-validation", "There was an error validating the log. Check either the page number or the date."); } } catch (DbUpdateConcurrencyException) { if (!ReadLogExists(readLog.ReadLogId)) { return(NotFound()); } else { throw; } } } ViewData["BookId"] = new SelectList(_context.Books, "BookId", "Name", readLog.BookId); return(View(readLog)); }
//记录 用户插入阅读隐私政策记录(参数:openid) public BaseViewModel SaveReadLog(string openid) { BaseViewModel baseView = new BaseViewModel(); if (openid == "") { baseView.Message = "参数为空"; baseView.ResponseCode = 2; } else { try { ReadLog log = new ReadLog(); log.openid = openid; log.CreateDate = DateTime.Now; _readLogRepository.Add(log); int a = _readLogRepository.SaveChanges(); if (a > 0) { baseView.Message = "保存成功"; baseView.ResponseCode = 0; } else { baseView.Message = "保存失败"; baseView.ResponseCode = 1; } } catch (Exception ex) { baseView.Message = "出现异常"; baseView.ResponseCode = 3; } } return(baseView); }
public ActionResult Edit(Contents contents) { Contents objOri = db.Contents.Find(contents.Id); if (ModelState.IsValid) { var c = Request.Files[0]; if (c != null && c.ContentLength > 0) { #region 保存新文件 int lastSlashIndex = c.FileName.LastIndexOf("\\"); string fileName = c.FileName.Substring(lastSlashIndex + 1, c.FileName.Length - lastSlashIndex - 1); int lastDotIndex = fileName.LastIndexOf("."); string fileType = fileName.Substring(lastDotIndex + 1); string guid = Guid.NewGuid().ToString(); string realName = guid + "." + fileType; string savePath = Path.Combine(Server.MapPath("/Documents/"), realName); c.SaveAs(savePath); #endregion #region 删除旧文件 bool isExists=System.IO.File.Exists(Path.Combine(Server.MapPath("/Documents/"), objOri.RealName)); if(isExists) { System.IO.File.Delete(Path.Combine(Server.MapPath("/Documents/"), objOri.RealName)); } #endregion objOri.Name = fileName.Substring(0, lastDotIndex); objOri.RealName = realName; objOri.Extension = fileType; objOri.Size = c.ContentLength; objOri.StatusId = 0; } objOri.ModelId = contents.ModelId; objOri.ProductId = contents.ProductId; objOri.Title = contents.Title; objOri.OrderNo = contents.OrderNo; objOri.EditerId = (int)Session["CurrentEmp"]; objOri.EditTime = DateTime.Now; db.Entry(objOri).State = EntityState.Modified; db.Database.ExecuteSqlCommand("delete from ReadLog where ContentId=" + objOri.Id); var readLog = new ReadLog { EmpId = (int)Session["CurrentEmp"], ContentId = objOri.Id, ReadTime = DateTime.Now }; db.ReadLog.Add(readLog); db.SaveChanges(); return Redirect("../Index/" + Request.QueryString["modelId"] + "?productId=" + Request.QueryString["productId"]); } IEnumerable<Menus> modelMenus = db.Database.SqlQuery<Menus>(string.Format(_queryStr, 30)); ViewBag.ModelId = new SelectList(modelMenus, "Id", "Title", contents.ModelId); IEnumerable<Menus> productMenus = db.Database.SqlQuery<Menus>(string.Format(_queryStr, 8)); ViewBag.ProductId = new SelectList(productMenus, "Id", "Title", contents.ProductId); return View(contents); }
public virtual void Add(ReadLog obj) { DbSet.Add(obj); }
public virtual void Update(ReadLog obj) { DbSet.Update(obj); }
private bool validateLog(ReadLog log) { //Log date cannot be after today if (log.LogDate.Date > DateTime.Today) { return(false); } var newBook = dbContext.Books.AsNoTracking().Include(b => b.ReadLogs).SingleOrDefault(b => b.BookId == log.BookId); var previousLogs = newBook.ReadLogs.OrderBy(l => l.PageNumber).ToList(); //If no other logs only check page number is between number of pages of book if (previousLogs.Count() == 0) { if (log.PageNumber <= newBook.NumberOfPages) { return(true); } } else { for (var index = 0; index < previousLogs.Count(); index++) { if (log.PageNumber < previousLogs[index].PageNumber) { if (index > 0) { //Only check lower bound if it exist. //Log with lower page num has to have earlier or equal date. if (previousLogs[index - 1].LogDate.Date > log.LogDate.Date) { return(false); } } //Check upper bound. //Log with higher page num has to have later or equal date. if (previousLogs[index].LogDate.Date < log.LogDate.Date) { return(false); } //Both checks passed return(true); } //New log has highest page num, check lower bound and number of pages if (index == previousLogs.Count() - 1) { //Log with lower page num has to have earlier or equal date. if (previousLogs[index].LogDate.Date > log.LogDate.Date) { return(false); } if (log.PageNumber <= newBook.NumberOfPages) { return(true); } } } } return(false); }
public FilePathResult GetFileFromDisk(int id) { ReadLog readLog = new ReadLog {EmpId = (int) Session["CurrentEmp"], ContentId = id, ReadTime = DateTime.Now}; db.ReadLog.Add(readLog); db.SaveChanges(); Contents contents = db.Contents.Find(id); string filePath = Path.Combine(Server.MapPath("/Documents/"), contents.RealName); return File(filePath, "text/plain", Url.Encode(contents.Name) + "." + contents.Extension);//非ie浏览器不需编码 }