public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                TimesheetEntry entry = new TimesheetEntry();
                if (entry != null)
                {
                    entry.EntryDate = collection["EntryDate"].ToDateTime();
                    entry.StartTime = collection["StartTime"].ToDateTime();
                    entry.EndTime = collection["EndTime"].ToDateTime();
                    entry.EntryCategory = collection["EntryCategory"];
                    entry.EntryEvent = collection["EntryEvent"];

                    entityService.AddToTimesheetEntries(entry);
                    entityService.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #2
0
        public ActionResult Test(TimesheetEntry entry)
        {
            TimesheetEntities ent = new TimesheetEntities();

            entry = ent.TimesheetEntries.First();

            return View(entry);
        }
 private TimeSheetEntry Build(TimesheetEntry entry)
 {
     string concatNotes = entry.TimeEntryNotes.Aggregate(string.Empty, (current, notes) => current + notes.Description);
     int totalTimeInSeconds = entry.TotalTime;
     decimal totalTimeInHours = totalTimeInSeconds / 3600;
     return new TimeSheetEntry(entry.AssignmentAttributeUid.ToString(CultureInfo.InvariantCulture),
         entry.TaskUid.ToString(CultureInfo.InvariantCulture),
         DateTime.ParseExact(entry.EntryDate, "M/dd/yyyy", CultureInfo.InvariantCulture), totalTimeInHours,
         concatNotes);
 }
Example #4
0
        public async Task <String> Post([FromBody] TimesheetEntry value)
        {
            await _db.Entries.AddAsync(value);

            await _db.SaveChangesAsync();

            var cacheConnection = _config.GetValue <string>("CacheConnection").ToString();
            var lazyConnection  = new Lazy <ConnectionMultiplexer>(() =>
            {
                return(ConnectionMultiplexer.Connect(cacheConnection));
            });

            IDatabase cache = lazyConnection.Value.GetDatabase();
            await cache.StringSetAsync($"{value.Name}-{value.Surname}", value.ToString());

            var cacheItem = await cache.StringGetAsync($"{value.Name}-{value.Surname}");

            lazyConnection.Value.Dispose();

            return(cacheItem);
        }
Example #5
0
        public async Task <IActionResult> Edit(int id, TimesheetEntryViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                TimesheetEntry timesheetEntry = _mapper.MapViewModelToTimesheetEntry(viewModel);

                if (NoEntryExistsForSameDateAndProjectExcludingSelf(timesheetEntry))
                {
                    try
                    {
                        _context.Update(timesheetEntry);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!TimesheetEntryExists(timesheetEntry.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.ErrorTitle   = "Error";
                    ViewBag.ErrorMessage = "User already has a timesheet entry for the same date and project";
                    return(View("CustomError"));
                }
            }
            return(View(viewModel));
        }
Example #6
0
        public void BtnDeleteSelectedEntry()
        {
            //Check if found
            if (EntriesCollection.Where(x => x.ID == SelectedEntry.ID).Count() == 0)
            {
                return;
            }

            //Find the entryrow
            EntryRow entryRow = EntriesCollection.FirstOrDefault(x => x.ID == SelectedEntry.ID);

            //Delete from datagrid
            EntriesCollection.Remove(entryRow);
            NotifyOfPropertyChange(() => EntriesCollection);

            VismaEntry vismaEntry;

            //Delete vismaentry from database and its timesheetentry if it was the last vismaentry.
            using (var ctx = new DatabaseDir.Database())
            {
                //Find the object in th database and delete
                vismaEntry = ctx.VismaEntries.Where(v => v.Id == SelectedEntry.ID).First();
                ctx.VismaEntries.Remove(vismaEntry);
                ctx.SaveChanges();
            }

            //Check and delete timesheetEntry if it no longer contains any vismaEntries
            using (var ctx = new DatabaseDir.Database())
            {
                //Search for other vismaentries with the same timesheet id
                List <VismaEntry> list = new List <VismaEntry>(ctx.VismaEntries.Where(x => x.TimesheetEntryID == vismaEntry.TimesheetEntryID));
                if (list.Count() == 0)
                {
                    TimesheetEntry timesheetEntry = ctx.TimesheetEntries.FirstOrDefault(x => x.Id == vismaEntry.TimesheetEntryID);
                    //If none, then delete
                    ctx.TimesheetEntries.Remove(timesheetEntry);
                    ctx.SaveChanges();
                }
            }
        }
Example #7
0
        public async Task <RedisValue> Put(int id, [FromBody] TimesheetEntry value)
        {
            var entry = await _db.Entries.FindAsync(id);

            entry = value;
            await _db.SaveChangesAsync();

            var cacheConnection = _config.GetValue <string>("CacheConnection").ToString();
            var lazyConnection  = new Lazy <ConnectionMultiplexer>(() =>
            {
                return(ConnectionMultiplexer.Connect(cacheConnection));
            });

            IDatabase cache = lazyConnection.Value.GetDatabase();
            await cache.StringSetAsync($"{value.EntryId}", value.ToString());

            var cacheItem = await cache.StringGetAsync($"{value.EntryId}");

            lazyConnection.Value.Dispose();

            return(cacheItem);
        }
Example #8
0
        public async Task <string> Post([FromBody] TimesheetEntry value)
        {
            await _db.Entries.AddAsync(value);

            await _db.SaveChangesAsync();

            var cacheConnection = _config.GetValue <string>("CacheConnection").ToString();
            var lazyConnection  = new Lazy <ConnectionMultiplexer>(() =>
            {
                return(ConnectionMultiplexer.Connect(cacheConnection));
            });

            IDatabase cache          = lazyConnection.Value.GetDatabase();
            var       serializeddata = JsonConvert.SerializeObject(value);
            await cache.StringSetAsync($"{value.EmployeeId}", serializeddata);

            var cacheItem = await cache.StringGetAsync($"{value.EmployeeId}");

            lazyConnection.Value.Dispose();

            return(cacheItem);
        }
        public async Task <IActionResult> Create(TimesheetEntryViewModel viewModel)
        {
            User user = await _userRepository.GetByGuid(User.FindFirstValue(ClaimTypes.NameIdentifier));

            viewModel.UserId       = user.Id;
            viewModel.UserFullName = string.Format("{0} {1}", user.FirstName, user.LastName);
            viewModel.ProjectName  = (await _projectRepository.GetById(viewModel.ProjectId)).Name;

            Project project = await _projectRepository.GetById(viewModel.ProjectId);

            Department department = await _departmentRepository.GetById(project.DepartmentOwnerId);

            TimesheetEntry entry = _mapper.ConvertFromViewModel(viewModel, project);

            entry.User = user;

            // Add TimesheetEntry to database
            await _timesheetEntryRepository.Create(entry);

            // Return to Index
            return(RedirectToAction(nameof(Index)));
        }
Example #10
0
        public async Task <IActionResult> Create(TimesheetEntryViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                TimesheetEntry timesheetEntry = _mapper.MapViewModelToTimesheetEntry(viewModel);

                if (NoEntryExistsForSameDateAndProject(timesheetEntry))
                {
                    _context.Add(timesheetEntry);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.ErrorTitle   = "Error";
                    ViewBag.ErrorMessage = "User already has a timesheet entry for the same date and project";
                    return(View("CustomError"));
                }
            }
            return(View(viewModel));
        }
Example #11
0
        public void Row_ProjectIsNull_FormatWithoutAProject()
        {
            int day   = 12;
            int month = 8;
            int year  = 2019;

            DateTime exampleDateTime = new DateTime(year, month, day);

            //Arrange
            TimesheetEntry tse = new TimesheetEntry
            {
                EmployeeID = 12,
                Date       = exampleDateTime,
                ProjectID  = null
            };

            VismaEntry ve = new VismaEntry
            {
                VismaID    = 34,
                Comment    = "test",
                Value      = 2,
                RateValue  = 20,
                LinkedRate = new Rate {
                    Type = "Arbejde"
                }
            };

            Row testRow = new Row(tse, ve, true);

            string expected = $"1242;1;{CommonValuesRepository.ColumnCSick};{tse.EmployeeID};{day}0{8}{2019};{day}0{8}{2019};{ve.VismaID};{ve.Comment};{ve.Value};;;;;;;;;;;;;;;;;;;;";

            //Act
            string actual = testRow.GetLine();


            //Assert
            Assert.AreEqual(expected, actual);
        }
        public IActionResult Put([FromBody] TimesheetEntry tse)
        {
            _logger.LogWarning($"About to update timesheet entry for id: {tse.Id}");

            if (tse == null)
            {
                return(BadRequest());
            }

            TimesheetEntry item = _context.TimesheetEntry
                                  .Where(b => b.Id == tse.Id)
                                  .FirstOrDefault();

            item.StartTime  = tse.StartTime;
            item.Details    = tse.Details;
            item.EndTime    = tse.EndTime;
            item.Code       = tse.Code;
            item.Chargeable = tse.IsEntryChargeable();

            _context.SaveChanges();

            return(Ok());
        }
        public async Task <string> Put(int id, [FromBody] TimesheetEntry value)
        {
            var entry = await _db.Entries.FindAsync(id);

            entry = value;
            await _db.SaveChangesAsync();

            var lazyConnection = new Lazy <ConnectionMultiplexer>(() =>
            {
                return(ConnectionMultiplexer.Connect(_config.GetValue <string>("CacheConnection")));
            });

            IDatabase cache = lazyConnection.Value.GetDatabase();

            var cacheItem = await cache.StringGetAsync($"{id}");

            var serializeddata = JsonConvert.SerializeObject(value);
            await cache.StringSetAsync($"{value.Id}", serializeddata);

            lazyConnection.Value.Dispose();

            return(JsonConvert.SerializeObject(value));
        }
        public async Task Put(int id, [FromBody] TimesheetEntry value)
        {
            var entry = await _db.Entries.FindAsync(id);

            entry = value;

            var cacheConnection = _config.GetValue <string>("CacheConnection").ToString(); //That is the connection string
            var lazyConnection  = new Lazy <ConnectionMultiplexer>(() =>                   //connecting to our Redis
            {
                //Connecting to Redis
                return(ConnectionMultiplexer.Connect(cacheConnection));
            });

            IDatabase cache = lazyConnection.Value.GetDatabase();//This is the connection to the Redis database

            //Adding to cache using this key which is the ID and the values
            string key = Convert.ToString(id);
            await cache.StringSetAsync(key, value.ToString());

            await cache.KeyPersistAsync(key); //Creating peristence on the key, in order for it to always be saved on cache

            await _db.SaveChangesAsync();
        }
Example #15
0
        private static void ApplyHourlyRate(TimesheetEntry entry, Rate rate)
        {
            //First a vismaEntry is created with values from the TimesheetEntry and the Rate.
            VismaEntry vismaEntry = new VismaEntry
            {
                VismaID          = rate.VismaID,
                RateID           = rate.Id,
                RateValue        = rate.RateValue,
                TimesheetEntryID = entry.Id,
                LinkedRate       = rate
            };

            // Then it finds the amount of time within the hourly rate by first checking which is larger, the start time of the rate or the entry.
            DateTime startTime = entry.StartTime > rate.StartTime ? entry.StartTime : rate.StartTime;

            // Then it checks which is smaller, the end time of the entry or the rate.
            DateTime endTime = entry.EndTime < rate.EndTime ? entry.EndTime : rate.EndTime;

            // Finally it calculates the timespan.
            TimeSpan interval = endTime - startTime;

            // Only the nearest quarter value is needed for precision.
            vismaEntry.Value = RoundToNearestQuarter(interval.TotalHours);

            //Breaktime is subtracted from normal work hours.
            if (rate.Name == "Normal")
            {
                vismaEntry.Value -= entry.BreakTime;
            }

            // Finally for a failsafe a check for the value of the new vismaEntry is done, to check if any hours were in fact in the timespan. Before adding it to the timesheetEntry.
            if (vismaEntry.Value > 0)
            {
                entry.vismaEntries.Add(vismaEntry);
            }
        }
Example #16
0
        public async Task <string> Post([FromBody] TimesheetEntry value)
        {
            await _db.Entries.AddAsync(value);

            await _db.SaveChangesAsync();

            var cacheConnection = _config.GetValue <string>("CacheConnection").ToString();



            //var lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
            //{
            //    string cacheConnection = ConfigurationManager.AppSettings["CacheConnection"].ToString();
            //    return ConnectionMultiplexer.Connect(cacheConnection);
            //});

            //// Connection refers to a property that returns a ConnectionMultiplexer
            //// as shown in the previous example.
            //IDatabase cache = lazyConnection.Value.GetDatabase();

            var data = await _db.Entries.Include(v => v.Employee).Include(c => c.Project).Include(c => c.Project.Client).FirstOrDefaultAsync(x => x.Employee.Id == value.Employee.Id);

            var lazyConnection = new Lazy <ConnectionMultiplexer>(() =>
            {
                return(ConnectionMultiplexer.Connect(cacheConnection));
            });

            IDatabase cache = lazyConnection.Value.GetDatabase();

            await cache.StringSetAsync(data.Id.ToString(), JsonConvert.SerializeObject(data));

            var cacheItem = await cache.StringGetAsync(data.Id.ToString());

            lazyConnection.Value.Dispose();
            return(cacheItem.ToString());;
        }
    //-------------------------------------------------------------------------
    protected void btnCreateNewRecord_Click(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();
        try
        {
            var qry = (from emp in ff.Employees
                       where emp.empId == Convert.ToInt32(Session["CurEmpId"])
                       select emp.approver).FirstOrDefault();

            TimesheetHeader tmp = new TimesheetHeader()
            {

                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId = Convert.ToInt32(Session["CurEmpId"]),
                status = "SAVED",
                approvedBy = qry,
                comments = "Comments"

            };

            var qry2 = (from th in ff.TimesheetHeaders
                        where th.empId == tmp.empId && th.tsDate == tmp.tsDate
                        select th).ToList();

            if (qry2.Count == 0)
            {
                ff.TimesheetHeaders.InsertOnSubmit(tmp);
                ff.SubmitChanges();
            }

            TimesheetEntry tmp2 = new TimesheetEntry()
            {
                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId = Convert.ToInt32(Session["CurEmpId"]),
                projId = Convert.ToInt32(ddlProjectId.SelectedValue),
                wpId = (ddlWpId.SelectedValue).ToString(),
                sun = Convert.ToInt32(tbSun.Text),
                sat = Convert.ToInt32(tbSat.Text),
                fri = Convert.ToInt32(tbFri.Text),
                thu = Convert.ToInt32(tbThu.Text),
                wed = Convert.ToInt32(tbWed.Text),
                tue = Convert.ToInt32(tbTue.Text),
                mon = Convert.ToInt32(tbMon.Text),
                notes = tbNote.Text

            };

            ff.TimesheetEntries.InsertOnSubmit(tmp2);
            ff.SubmitChanges();
            lblteSubmitSuccess.Text = "Submit has been saved.";
            divNewRecord.Visible = false;
            btnNewRecord.Visible = true;
            divtotal.Visible = true;
            tbFri.Text = String.Empty;
            tbMon.Text = String.Empty;
            tbNote.Text = String.Empty;
            //tbProjectID.Text = String.Empty;
            tbSat.Text = String.Empty;
            tbSun.Text = String.Empty;
            tbThu.Text = String.Empty;
            tbTue.Text = String.Empty;
            tbWed.Text = String.Empty;
            //tbWpID.Text = String.Empty;

        }
        catch (Exception myException)
        {
            lblteSubmitSuccess.Text = "ENTRY ALREADY EXISTS";
            // Label1.Text = "You have sumbitted the record before, Cannot insert duplicate record into the database!!!";

        }
    }
 public bool IsSatisfied(TimesheetEntry tse)
 {
     return(tse.Timesheet.IsApproved() && tse.Code.Equals(this.projCode));
 }
Example #19
0
 public void UpdateTimesheetEntry(TimesheetEntry tse)
 {
     _context.Entry(tse).State = EntityState.Modified;
 }
 partial void DeleteTimesheetEntry(TimesheetEntry instance);
 partial void InsertTimesheetEntry(TimesheetEntry instance);
	private void detach_TimesheetEntries(TimesheetEntry entity)
	{
		this.SendPropertyChanging();
		entity.TimesheetHeader = null;
	}
Example #23
0
 public void UpdateTimesheetEntry(TimesheetEntry entry)
 {
     Database.UpdateTimesheetEntry(entry);
 }
Example #24
0
 public TimesheetEntry AddTimesheetEntry(TimesheetEntry newEntry)
 {
     return(Database.AddTimesheetEntry(newEntry));
 }
Example #25
0
        public async Task Post([FromBody] TimesheetEntry value)
        {
            await _db.Entries.AddAsync(value);

            await _db.SaveChangesAsync();
        }
 public TimeSheetEntryBuilder(TimesheetEntry[] timesheetEntries)
 {
     if (timesheetEntries == null) throw new ArgumentNullException("timesheetEntries");
     _timesheetEntries = timesheetEntries;
 }
Example #27
0
 public void DeleteTimesheetEntry(TimesheetEntry tse)
 {
     _context.Entry(tse).State = EntityState.Deleted;
 }
Example #28
0
 private static bool TypesCompatible(TimesheetEntry entry, Rate rate)
 {
     return(entry.SelectedTypeComboBoxItem == rate.Type || (entry.SelectedTypeComboBoxItem == "Forskudttid" && rate.Name == "Normal"));
 }
Example #29
0
 private bool NoEntryExistsForSameDateAndProject(TimesheetEntry timesheetEntry)
 {
     return(_context.TimesheetEntries.FirstOrDefault(e => e.DateCreated == timesheetEntry.DateCreated &&
                                                     e.RelatedUser.UserName.Equals(timesheetEntry.RelatedUser.UserName) &&
                                                     e.RelatedProject.Id == timesheetEntry.RelatedProject.Id) == null);
 }
Example #30
0
 public abstract string Validate(TimesheetEntry timesheetEntry);
Example #31
0
        private bool TimesheetEntryAuthorizedAsync(TimesheetEntry entry)
        {
            var authorizationResult = _authorizationService.AuthorizeAsync(User, entry, "SameTimesheetEntryCreator").Result;

            return(authorizationResult.Succeeded);
        }
Example #32
0
 protected TimesheetEntryViewModel()
 {
     Timesheet = new TimesheetEntry();
 }
Example #33
0
        private TimesheetEntry GetActualTimesheetEntry()
        {
            var actualTime = GetActualTime();
            var actualTimesheet = GetActualTimesheet();

            var actualTimesheetEntry =
                actualTimesheet.TimesheetEntries.FirstOrDefault(te =>
                    (te.WorkStart.HasValue && te.WorkStart.Value.Day == actualTime.Day)
                    || (te.WorkEnd.HasValue && te.WorkEnd.Value.Day == actualTime.Day)
                    || (te.LunchBreakStart.HasValue && te.LunchBreakStart.Value.Day == actualTime.Day)
                    || (te.LunchBreakEnd.HasValue && te.LunchBreakEnd.Value.Day == actualTime.Day));
            if (actualTimesheetEntry == null)
            {
                actualTimesheetEntry = new TimesheetEntry();
                actualTimesheet.TimesheetEntries.Add(actualTimesheetEntry);
            }

            return actualTimesheetEntry;
        }
	private void detach_TimesheetEntries(TimesheetEntry entity)
	{
		this.SendPropertyChanging();
		entity.WorkPackage = null;
	}
        public async Task <IActionResult> Delete(int id)
        {
            TimesheetEntry entry = await _timesheetEntryRepository.GetById(id);

            return(View(_mapper.ConvertToViewModel(entry)));
        }
 partial void UpdateTimesheetEntry(TimesheetEntry instance);
Example #37
0
    //-------------------------------------------------------------------------
    protected void btnCreateNewRecord_Click(object sender, EventArgs e)
    {
        FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext();

        try
        {
            var qry = (from emp in ff.Employees
                       where emp.empId == Convert.ToInt32(Session["CurEmpId"])
                       select emp.approver).FirstOrDefault();


            TimesheetHeader tmp = new TimesheetHeader()
            {
                tsDate     = Convert.ToDateTime(Session["CurrentDate"]),
                empId      = Convert.ToInt32(Session["CurEmpId"]),
                status     = "SAVED",
                approvedBy = qry,
                comments   = "Comments"
            };


            var qry2 = (from th in ff.TimesheetHeaders
                        where th.empId == tmp.empId && th.tsDate == tmp.tsDate
                        select th).ToList();

            if (qry2.Count == 0)
            {
                ff.TimesheetHeaders.InsertOnSubmit(tmp);
                ff.SubmitChanges();
            }

            TimesheetEntry tmp2 = new TimesheetEntry()
            {
                tsDate = Convert.ToDateTime(Session["CurrentDate"]),
                empId  = Convert.ToInt32(Session["CurEmpId"]),
                projId = Convert.ToInt32(ddlProjectId.SelectedValue),
                wpId   = (ddlWpId.SelectedValue).ToString(),
                sun    = Convert.ToInt32(tbSun.Text),
                sat    = Convert.ToInt32(tbSat.Text),
                fri    = Convert.ToInt32(tbFri.Text),
                thu    = Convert.ToInt32(tbThu.Text),
                wed    = Convert.ToInt32(tbWed.Text),
                tue    = Convert.ToInt32(tbTue.Text),
                mon    = Convert.ToInt32(tbMon.Text),
                notes  = tbNote.Text
            };

            ff.TimesheetEntries.InsertOnSubmit(tmp2);
            ff.SubmitChanges();
            lblteSubmitSuccess.Text = "Submit has been saved.";
            divNewRecord.Visible    = false;
            btnNewRecord.Visible    = true;
            divtotal.Visible        = true;
            tbFri.Text  = String.Empty;
            tbMon.Text  = String.Empty;
            tbNote.Text = String.Empty;
            //tbProjectID.Text = String.Empty;
            tbSat.Text = String.Empty;
            tbSun.Text = String.Empty;
            tbThu.Text = String.Empty;
            tbTue.Text = String.Empty;
            tbWed.Text = String.Empty;
            //tbWpID.Text = String.Empty;
        }
        catch (Exception myException)
        {
            lblteSubmitSuccess.Text = "ENTRY ALREADY EXISTS";
            // Label1.Text = "You have sumbitted the record before, Cannot insert duplicate record into the database!!!";
        }
    }
 public bool IsSatisfied(TimesheetEntry tse)
 {
     return(tse.Chargeable && tse.Code.Equals(this.projCode));
 }
Example #39
0
 public void InsertTimesheetEntry(TimesheetEntry tse)
 {
     _context.TimesheetEntry.Add(tse);
 }