public void Add(TimeLog timeLog) { string dataRow = $"{timeLog.Date}{_delimeter}{timeLog.LastName}{_delimeter}" + $"{timeLog.WrokingHours}{_delimeter}{timeLog.Comment}\n"; File.AppendAllText(_path, dataRow); }
/// <summary> /// Gets all working times from database. /// </summary> /// <returns>The list of TimeLog objects from db</returns> public List <TimeLog> GetAllWorkingTimes() { List <TimeLog> loglist = new List <TimeLog>(); SqlConnection sqlconn = new SqlConnection(connString); using (sqlconn) { SqlCommand command = new SqlCommand( "SELECT * FROM dbo.Logs", sqlconn); sqlconn.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { TimeLog tl = new TimeLog(); tl.id = Convert.ToInt32(reader["LogID"]); tl.Project = reader["Project"].ToString(); tl.Comment = reader["Comment"].ToString(); tl.Date = reader["Date"].ToString(); tl.Time = Convert.ToInt32(reader["Time"]); loglist.Add(tl); } } reader.Close(); sqlconn.Close(); return(loglist); } }
private static void AddExampleData(ApiContext context) { var testProject1 = new Project { Id = 1, Name = "e-conomic Interview" }; var testProject2 = new Project { Id = 2, Name = "Secret project" }; context.Projects.Add(testProject1); context.Projects.Add(testProject2); var testTimeLog1 = new TimeLog { TimeSpent = 2.5, Date = DateTime.Now, ProjectId = testProject1.Id }; var testTimeLog2 = new TimeLog { TimeSpent = 5.23, Date = DateTime.Now, ProjectId = testProject1.Id }; context.TimeLogs.Add(testTimeLog1); context.TimeLogs.Add(testTimeLog2); context.SaveChanges(); }
public void TrackTime_ChiefEmployee_ShouldReturnTrue() { // arrange var expectedLastName = "TestUser"; UserSessions.Sessions.Add(expectedLastName); var timeLog = new TimeLog { Date = DateTime.Now, WorkHours = 1, LastName = expectedLastName, Comment = Guid.NewGuid().ToString() }; _timesheetRepositoryMock .Setup(x => x.Add(timeLog)); _employeeRepositoryMock .Setup(x => x.GetEmployee(expectedLastName)) .Returns(() => new ChiefEmployee(expectedLastName, 0m, 0m)) .Verifiable(); // act var result = _service.TrackTime(timeLog, expectedLastName); // assert _employeeRepositoryMock.VerifyAll(); _timesheetRepositoryMock.Verify(x => x.Add(timeLog), Times.Once); Assert.IsTrue(result); }
public List <TimeLog> GetAll() { List <TimeLog> result = new List <TimeLog>(); FileStream fs = new FileStream(this.filePath, FileMode.OpenOrCreate); StreamReader sr = new StreamReader(fs); try { while (!sr.EndOfStream) { TimeLog tl = new TimeLog(); tl.Id = Convert.ToInt32(sr.ReadLine()); tl.TaskId = Convert.ToInt32(sr.ReadLine()); tl.UserId = Convert.ToInt32(sr.ReadLine()); tl.HoursWork = Convert.ToInt32(sr.ReadLine()); tl.DateOfCreation = Convert.ToDateTime(sr.ReadLine()); result.Add(tl); } } finally { sr.Close(); fs.Close(); } return(result); }
public async Task <IActionResult> Edit(int id, [Bind("TimeLogID,Username,ActivityID,StartTime,EndTime")] TimeLog timeLog) { if (id != timeLog.TimeLogID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(timeLog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TimeLogExists(timeLog.TimeLogID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["ActivityID"] = new SelectList(_context.Activities.Where(o => o.Username == User.Identity.Name), "ActivityID", "Username", timeLog.ActivityID); return(View(timeLog)); }
private int GetNextId() { FileStream fs = new FileStream(this.filePath, FileMode.OpenOrCreate); StreamReader sr = new StreamReader(fs); int id = 1; try { while (!sr.EndOfStream) { TimeLog tl = new TimeLog(); tl.Id = Convert.ToInt32(sr.ReadLine()); tl.TaskId = Convert.ToInt32(sr.ReadLine()); tl.UserId = Convert.ToInt32(sr.ReadLine()); tl.HoursWork = Convert.ToInt32(sr.ReadLine()); tl.DateOfCreation = Convert.ToDateTime(sr.ReadLine()); if (id <= tl.Id) { id = tl.Id + 1; } } } finally { sr.Close(); fs.Close(); } return(id); }
[TestCase("Сидоров", 1000, 281000)] // ставка за час = 1000; 1000 * 281 public void GetEmployeeReport_ShouldReturnReportPerSeveralMonth(string expectedLastName, decimal salary, decimal expectedTotal) { //arrange var timesheetRepositoryMock = new Mock <ITimesheetRepository>(); var employeeRepositoryMock = new Mock <IEmployeeRepository>(); var expectedTotalHours = 281m; employeeRepositoryMock .Setup(x => x.GetEmployee(It.Is <string>(x => x == expectedLastName))) .Returns(() => new StaffEmployee { LastName = expectedLastName, Salary = salary }) .Verifiable(); timesheetRepositoryMock .Setup(x => x.GetTimeLogs(It.Is <string>(x => x == expectedLastName))) .Returns(() => { TimeLog[] timeLogs = new TimeLog[35]; DateTime dateTime = new DateTime(2020, 11, 1); timeLogs[0] = new TimeLog { LastName = expectedLastName, Comment = Guid.NewGuid().ToString(), Date = dateTime, WorkingHours = 9 }; for (int i = 1; i < timeLogs.Length; i++) { dateTime = dateTime.AddDays(1); timeLogs[i] = new TimeLog { LastName = expectedLastName, Comment = Guid.NewGuid().ToString(), Date = dateTime, WorkingHours = 8 }; } return(timeLogs); }) .Verifiable(); var service = new ReportService(timesheetRepositoryMock.Object, employeeRepositoryMock.Object); //act var result = service.GetEmployeeReport(expectedLastName); //assert Assert.IsNotNull(result); Assert.AreEqual(expectedLastName, result.LastName); Assert.IsNotNull(result.TimeLogs); Assert.IsNotEmpty(result.TimeLogs); Assert.AreEqual(expectedTotal, result.Bill); Assert.AreEqual(expectedTotalHours, result.TotalHours); }
public void TrackTime_Freelancer_ShouldReturnFalse() { // arrange var expectedLastName = "TestUser"; UserSessions.Sessions.Add(expectedLastName); var timeLog = new TimeLog { Date = DateTime.Now.AddDays(-3), WorkHours = 2, LastName = expectedLastName, Comment = Guid.NewGuid().ToString() }; _employeeRepositoryMock .Setup(x => x.GetEmployee(expectedLastName)) .Returns(() => new FreelancerEmployee(expectedLastName, 0m)) .Verifiable(); // act var result = _service.TrackTime(timeLog, expectedLastName); // assert Assert.IsFalse(result); _employeeRepositoryMock.VerifyAll(); _timesheetRepositoryMock.Verify(x => x.Add(timeLog), Times.Never); }
public void TrackTime_ShouldReturnTrue() { //arrange var expectedLastName = "TestUser"; UserSessions.Sessions.Add(expectedLastName); var timeLog = new TimeLog { Date = new DateTime(), WorkingHours = 1, LastName = expectedLastName, Comment = Guid.NewGuid().ToString() }; var timesheetRepositoryMock = new Mock <ITimesheetRepository>(); timesheetRepositoryMock .Setup(x => x.Add(timeLog)) .Verifiable(); var service = new TimesheetService(timesheetRepositoryMock.Object); //act var result = service.TrackTime(timeLog); //assert timesheetRepositoryMock.Verify(x => x.Add(timeLog), Times.Once); Assert.IsTrue(result); }
public void TrackTime_ShouldReturnFalse(int hours, string lastName) { //arrange var timeLog = new TimeLog { Date = new DateTime(), WorkingHours = hours, LastName = lastName, Comment = Guid.NewGuid().ToString() }; var timesheetRepositoryMock = new Mock <ITimesheetRepository>(); timesheetRepositoryMock .Setup(x => x.Add(timeLog)) .Verifiable(); var service = new TimesheetService(timesheetRepositoryMock.Object); //act var result = service.TrackTime(timeLog); //assert timesheetRepositoryMock.Verify(x => x.Add(timeLog), Times.Never); Assert.IsFalse(result); }
public async Task <IActionResult> PutTimeLog(int id, TimeLog timeLog) { if (id != timeLog.TimeLogId) { return(BadRequest()); } _context.Entry(timeLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TimeLogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool TrackTime(TimeLog timeLog, string lastName) { bool isValid = timeLog.WorkHours > 0 && timeLog.WorkHours <= 24 && !string.IsNullOrWhiteSpace(timeLog.LastName); var employee = _employeeRepository.GetEmployee(timeLog.LastName); if (!isValid || employee == null) { return(false); } if (employee is FreelancerEmployee) { if (DateTime.Now.AddDays(-2) > timeLog.Date) { return(false); } } if (employee is FreelancerEmployee || employee is StaffEmployee) { if (timeLog.LastName != lastName) { return(false); } } _timesheetRepository.Add(timeLog); return(true); }
public void QuickScanBombCount() { if (BombCountRectangles == null) { throw new InvalidOperationException(); } var captureLog = TimeLog.Stopwatch("Capture Bomb Count"); var bitmaps = BombCountRectangles.Select(GetCapture).ToArray(); captureLog.Dispose(); var readLog = TimeLog.Stopwatch("Read Face"); var bombCountDigits = bitmaps.Select(bitmap => { using (var integerMap = new IntegerMap(bitmap)) { var bombCountIcon = bombCountScanner.QuickRead(integerMap, Point.Empty); if (bombCountIcon == null) { throw new GameScanException("Scan bomb count failed"); } return(MapBombCount(bombCountIcon)); } }); BombCount = bombCountDigits.Aggregate((total, curr) => total * 10 + curr); readLog.Dispose(); }
public void QuickScanFace() { if (FaceRectangle == Rectangle.Empty) { throw new InvalidOperationException(); } var captureLog = TimeLog.Stopwatch("Capture Face"); var bitmap = GetCapture(FaceRectangle); captureLog.Dispose(); var readLog = TimeLog.Stopwatch("Read Face"); using (var integerMap = new IntegerMap(bitmap)) { var faceIcon = faceScanner.QuickRead(integerMap, Point.Empty); if (faceIcon == null) { throw new GameScanException("Scan face failed"); } Face = MapFace(faceIcon); } readLog.Dispose(); }
public ContentResult Save(string objdata, string value) { JsonObject js = new JsonObject(); js.StatusCode = 200; js.Message = "Upload Success"; try { TimeLog obj = JsonConvert.DeserializeObject <TimeLog>(objdata); obj = TimeLogManager.Update(obj); if (obj.TimeLogId == 0) { js.StatusCode = 400; js.Message = "Has Errors. Please contact Admin for more information"; } else { js.Data = obj; } } catch (Exception objEx) { js.StatusCode = 400; js.Message = objEx.Message; } return(Content(JsonConvert.SerializeObject(js), "application/json")); }
/// <summary> /// use for setting up default value /// </summary> /// <returns></returns> public ActionResult Update(int TimeLogId, string TargetID = "TimeLoglist") { TimeLog objItem = TimeLogManager.GetById(TimeLogId); objItem.TargetDisplayID = TargetID; return(View(ViewFolder + "Create.cshtml", objItem)); }
public ActionResult Create(TimeLog model) { try { if (ModelState.IsValid) { //model.CreatedUser = CurrentUser.UserName; if (model.TimeLogId != 0) { //get default value // TimeLog b = TimeLogManager.GetById(model.TimeLogId); TimeLogManager.Update(model); } else { // TODO: Add insert logic here // model.CreatedDate = SystemConfig.CurrentDate; TimeLogManager.Add(model); } return(View(ViewFolder + "list.cshtml", TimeLogManager.GetAll())); } } catch { return(View(model)); } return(View(model)); }
private void AddToTimeLog() { if (TimeLog != null) { TimeLog.AddActivity(currentActivity); } }
public static void RemoveCache(TimeLog objItem) { HttpCache.RemoveByPattern(SETTINGS_ALL_KEY); HttpCache.RemoveByPattern(string.Format(SETTINGS_ID_KEY, objItem.TimeLogId)); //HttpCache.RemoveByPattern(string.Format(SETTINGS_User_KEY, objItem.CreatedUser)); HttpCache.RemoveSearchCache(SystemConfig.AllowSearchCache, SETTINGS_Search_KEY); }
public TimeLog GetById(int id) { FileStream fs = new FileStream(this.filePath, FileMode.OpenOrCreate); StreamReader sr = new StreamReader(fs); try { while (!sr.EndOfStream) { TimeLog tl = new TimeLog(); tl.Id = Convert.ToInt32(sr.ReadLine()); tl.TaskId = Convert.ToInt32(sr.ReadLine()); tl.UserId = Convert.ToInt32(sr.ReadLine()); tl.HoursWork = Convert.ToInt32(sr.ReadLine()); tl.DateOfCreation = Convert.ToDateTime(sr.ReadLine()); if (tl.Id == id) { return(tl); } } } finally { sr.Close(); fs.Close(); } return(null); }
public TimeLog[] GetTimeLogs(string lastName) { var data = File.ReadAllText(_path); var dataRows = data.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); var timeLogs = new List <TimeLog>(); foreach (var dataRow in dataRows) { if (dataRow.Contains(lastName)) { var timeLog = new TimeLog(); var dataMembers = dataRow.Split(_delimeter); timeLog.Comment = dataMembers[0]; timeLog.Date = DateTime.TryParse(dataMembers[1], out var date) ? date : new DateTime(); timeLog.LastName = dataMembers[2]; timeLog.WorkingHours = int.TryParse(dataMembers[3], out var workingHours) ? workingHours : 0; timeLogs.Add(timeLog); } } return(timeLogs.ToArray()); }
public async Task <bool> DeleteLog(int logId) { TimeLog logToDelete = await _context.TimeLogs.FirstOrDefaultAsync(x => x.Id == logId); await DeleteAsync(logToDelete); return(true); }
public override void Analyze(TimeLogReportingServiceContext context, TimeLog workitem) { ValidateByrole(context, workitem, TaskOwnerType.Architect, "Architect code review"); ValidateByrole(context, workitem, TaskOwnerType.Peer, "Peer code review"); ValidateByrole(context, workitem, TaskOwnerType.Developer, "Development"); ValidateByrole(context, workitem, TaskOwnerType.Tester, "Testing"); ValidateByrole(context, workitem, TaskOwnerType.Team, "Generic"); }
public IActionResult Add([FromBody] TimeLog timeLog) { if (_timesheetService.TrackTime(timeLog, timeLog.EmployeeLogin)) { return(Ok(timeLog.Comment)); } return(NoContent()); }
public void Add(TimeLog timeLog) { var dataRow = $"{timeLog.LastName}{_delimeter}" + $"{timeLog.WorkingTimeHours}{_delimeter}" + $"{timeLog.Date}\n"; File.AppendAllText(_path, dataRow); }
public ActionResult DeleteConfirmed(int id) { TimeLog timeLog = db.TimeLogs.Find(id); db.TimeLogs.Remove(timeLog); db.SaveChanges(); return(RedirectToAction("Index")); }
private TimeLog GetPreviousEntry(TimeLog currentItem) { IQueryable <TimeLog> results = QueryResultset(); Int32 index = results.ToList().IndexOf(results.Where(x => x.Id == currentItem.Id).First()); TimeLog prevEntry = results.ToList().ElementAt(index - 1); return(prevEntry); }
public void Add(TimeLog timeLog) { var dataRow = $"{timeLog.Comment}{DELIMETER}" + $"{timeLog.Date}{DELIMETER}" + $"{timeLog.LastName}{DELIMETER}" + $"{timeLog.WorkingHours}\n"; File.AppendAllText(PATH, dataRow, System.Text.Encoding.UTF8); }
//以后不用这个了 //public void NewOneTime(Guid id) { // if (TimeLog.Count(m=>m.ID==id)==0) // { // TimeLog.Add(new OneTime { ID = id, startDate = DateTime.Now ,endDate= DateTime.Now, Log="",leaveSecound=0}); // } //} public void NewOneTime(Guid id, string section, string file, string log, string formname) { if (TimeLog.Count(m => m.ID == id) == 0) { TimeLog.Add(new OneTime { ID = id, startDate = DateTime.Now, endDate = DateTime.Now, Log = log, leaveSecound = 0, section = section, fileFullName = file, formName = formname }); } }
public static void LoadTilesets(GameProject project, GraphicsDevice device) { var timeLog = new TimeLog(); if (project.Tilesets != null) { foreach (Tileset set in project.Tilesets) { set.LoadTexture(device); } } timeLog.Log("load tilesets"); }
private void btnReset_Click(object sender, EventArgs e) { var caption = "Reset database"; var message = "Are you sure you want to clear all database entries?\r\nThis operation cannot be undone."; if(DialogResult.Yes != MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) return; var log = new TimeLog(); log.ResetDb(); RefreshReport(); }
public static void LoadMapObjectSprites(GameProject project, GraphicsDevice device) { var timeLog = new TimeLog(); if (project.MapObjects != null) { foreach (var obj in project.MapObjects) { if (!string.IsNullOrEmpty(obj.SpriteInfo.Name)) { var texture = ContentLoader.LoadTexture(device, "Sprites/Objects/" + obj.SpriteInfo.Name); obj.Animation = new SpriteAnimation(texture, 100, 1); obj.Animation.Origin = obj.Origin; } } } timeLog.Log("load sprites"); }
public LotuzForm() { var constructorLog = new TimeLog(); InitializeComponent(); splitContainer1.Enabled = false; editorToolbar.Enabled = false; itmOptions.Enabled = false; objectSelectionControl1.Editor = this; enemySelectionControl1.Editor = this; textureSelectionControl.Editor = this; npcSelectionControl1.Editor = this; mapControl.Editor = this; mapControl.Content = new ContentManager(mapControl.Services, "Content"); UpdateTileTextureSelectionControlSize(); pnlMap.MouseWheel += pnlMap_MouseWheel; LoadConfig(); CheckContentFolder(); CurrentMapIndex = -1; CurrentObject = new MapObject(); Objects = new List<GameObject>(); deletedMapLayers = new List<Guid>(); CurrentLayerType = LayerType.MapLayer; cbbLayerType.SelectedIndex = 0; cbbZoom.SelectedIndex = 3; AddButtonsToList(); mapControl.ControlLoaded += MapControl_ControlLoaded; constructorLog.Log("editor constructor"); }
void ProcessLogItemsSince(DateTime when, Action<LogEntry> action) { var log = new TimeLog(); var entries = log.GetEntriesSince(when); foreach (var entry in entries) action(entry); }
protected override void Initialize() { var log = new TimeLog(); SpriteBatch = new SpriteBatch(GraphicsDevice); basicEffect = new BasicEffect(GraphicsDevice); basicEffect.VertexColorEnabled = true; MapObjectOpacity = 100; ScrollAmount = Vector2.Zero; PaintedAreaStart = new Vector2(-1, -1); PaintedAreaCurrentPosition = new Vector2(-1, -1); PreviewSelectedObjectOnMap = true; // Hook the idle event to constantly redraw our animation. Application.Idle += delegate { Invalidate(); }; ControlLoaded?.Invoke(this); log.Log("mapcontrol constructor"); }
private void cmdRemove_Click(object sender, EventArgs e) { var caption = "Delete entry"; var message = "Are you sure you want to delete this log entry?\r\nThis operation cannot be undone."; if (DialogResult.Yes != MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) return; var item = (LogEntry) lstEntries.SelectedItems[0].Tag; ITimeLog log = new TimeLog(); log.Remove(item); RefreshReport(); }
private void cmdMerge_Click(object sender, EventArgs e) { var items = lstEntries.SelectedItems.Cast<ListViewItem>().Select(i => (LogEntry) i.Tag); var duration = items.Sum(i => i.Duration); var comments = items.Where(i => !string.IsNullOrEmpty(i.Comment)).Select(i => i.Comment).ToArray(); string desc = string.Join(", ", comments); var itemList = items.ToList(); var frm = new MergeForm(itemList, desc); if(DialogResult.OK != frm.ShowDialog()) return; desc = frm.Description; ITimeLog log = new TimeLog(); log.Merge(itemList, desc); RefreshReport(); }
public void Execute() { var log = new TimeLog(); m_currentGroup = null; m_data = GetData(log); }
private void cmdEdit_Click(object sender, EventArgs e) { var item = (LogEntry) lstEntries.SelectedItems[0].Tag; var frm = new EntryEditor(item); if(DialogResult.OK != frm.ShowDialog()) return; ITimeLog log = new TimeLog(); log.Update(item); RefreshReport(); }