public ActionResult AddCompany(CompanyViewModel company) { var user = User.Identity.GetUserId(); Guid guid = Guid.NewGuid(); // company.CompanyId = guid; if (db.Companies.All(x => x.Password != company.Password)) { db.Companies.Add(new Company { CompanyId = guid, CompanyName = company.CompanyName, CompanyPhoneNumber = company.PhoneNumber, Email = company.Email, Password = company.Password, ClientBillInterval = company.ClientBillInterval, EmployeePayInterval = company.EmployeePayInterval, DateJoined = DateTime.Today }); var newCompany = db.Companies.SingleOrDefault(x => x.CompanyId == guid && x.Password == company.Password); db.CompanyEmployees.Add(new CompanyEmployee { EmployeeId = user, CompanyId = guid }); db.IdentityUserRoles.Add(new IdentityUserRole { RoleId = Ceo, UserId = user }); db.SaveChanges(); return(RedirectToAction("Dashboard", "Home")); } else { //This would be a terrible security leak we would have to send a urgent message to this company to reset there password ModelState.AddModelError("password", "That password is invalid please add a new password"); // var duplicate= db.Companies.FirstOrDefault(x => x.Password == company.Password); return(View()); } }
public void Delete(int tid) { var T = DbContext.Tasks.Find(tid); DbContext.Remove(T); DbContext.SaveChanges(); }
public ActionResult BillClients(string time) { var Total = TimeWorked(time); foreach (var item in Total) { var s = Convert.ToString(item.Value); var Hours = Convert.ToDecimal(TimeSpan.Parse(s).Hours); var Minutes = Convert.ToDecimal(TimeSpan.Parse(s).Minutes); var Seconds = Convert.ToDecimal(TimeSpan.Parse(s).Seconds); var findUser = User.Identity.GetUserId(); var company = db.CompanyEmployees.SingleOrDefault(x => x.EmployeeId == findUser); var rate = db.ClientProjects.Include("Client").FirstOrDefault(x => x.Client.CompanyId == company.CompanyId && x.ProjectId == item.Key); var payPerHour = rate.BillRate * Hours; var perMinute = rate.BillRate / 60; var payPerMinute = perMinute * Minutes; var perSecond = rate.BillRate / 3600; var payPerSecond = perSecond * Seconds; var Bill = payPerHour + payPerMinute + payPerSecond; var TotalBill = Bill.GetValueOrDefault(); if (TotalBill > 0) { db.ClientBills.Add(new ClientBill { CompanyId = company.CompanyId, ClientId = rate.ClientId, Bill = TotalBill, DateBilled = DateTime.Today, TimeWorked = item.Value, ProjectId = rate.ProjectId }); } } db.SaveChanges(); return(RedirectToAction("Index")); }
public void Delete(int empId) { var T = DbContext.Employees.Find(empId); DbContext.Remove(T); DbContext.SaveChanges(); }
public ActionResult PunchIn(int id) { var FindUser = User.Identity.GetUserId(); DateTime date = DateTime.Now; TimeSpan span = new TimeSpan(16, 0, 0); DateTime time = date - span; ViewBag.Error = db.TimeSheetEntries.Any(x => x.EmployeeId == FindUser && x.StartTime <date && x.StartTime> time && x.EndTime == null); ViewBag.DifferentDate = db.TimeSheetEntries.Any(x => x.EmployeeId == FindUser && x.StartTime < time && x.EndTime == null); if (db.TimeSheetEntries.Any(x => x.EmployeeId == FindUser && x.StartTime < date && x.StartTime > time && x.EndTime == null)) { ModelState.AddModelError("Error", "You never punched out from your last job"); return(PartialView()); } else { //what am i loking ffor here var project = db.Projects.Find(id); Stopwatch timer = Stopwatch.StartNew(); db.TimeSheetEntries.Add(new TimeSheetEntry { EmployeeId = FindUser, ProjectId = project.ProjectId, StartTime = DateTime.Now, CompanyId = project.CompanyId }); db.SaveChanges(); return(PartialView()); } }
public ActionResult Create(CreateClientModel client) { var UserId = User.Identity.GetUserId(); var company = db.CompanyEmployees.SingleOrDefault(x => x.EmployeeId == UserId); if (ModelState.IsValid) { //errors 1) both bools unselected 2)both selected 3)billByProject selected and bill rate is not null 4)billByClient is true and bill rate is null if (db.Clients.Any(x => x.ClientEmail == client.ClientEmail && x.CompanyId == company.CompanyId)) { //Make this partial view return(RedirectToAction("EmailError")); } else if (client.BillByProject == false && client.BillByClient == false) { ModelState.AddModelError("bools", "You must select either to bill by client or project"); return(View()); } else if (client.BillByClient == true && client.BillByProject == true) { return(View()); } else if (client.BillByProject == true && client.BillRate != null) { return(View()); } else if (client.BillByClient == true && client.BillRate == null) { return(View()); } //If email is different but everthing else is the same add new row in client else { if (client.BillByClient == true) { client.BillByProject = false; } else if (client.BillByProject == true) { client.BillByClient = false; client.BillRate = null; } db.Clients.Add(new Client { CompanyId = company.CompanyId, ClientName = client.ClientName, ClientEmail = client.ClientEmail, ClientPhoneNumber = client.ClientPhoneNumber, ClientAddress = client.ClientAddress, BillByClient = client.BillByClient, BillRate = client.BillRate, BillByProject = client.BillByProject, IsDeleted = false }); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(client)); }
public ActionResult EmployeePay(string time) { var Total = TimeWorked(time); foreach (var item in Total) { var s = Convert.ToString(item.Value); var Hours = Convert.ToDecimal(TimeSpan.Parse(s).Hours); var Minutes = Convert.ToDecimal(TimeSpan.Parse(s).Minutes); var Seconds = Convert.ToDecimal(TimeSpan.Parse(s).Seconds); var findUser = User.Identity.GetUserId(); var company = db.CompanyEmployees.SingleOrDefault(x => x.EmployeeId == findUser); var rate = db.CompanyEmployees.SingleOrDefault(x => x.CompanyId == company.CompanyId && x.EmployeeId == item.Key); var payPerHour = rate.PayRate * Hours; var perMinute = rate.PayRate / 60; var payPerMinute = perMinute * Minutes; var perSecond = rate.PayRate / 3600; var payPerSecond = perSecond * Seconds; decimal TotalBill = payPerHour + payPerMinute + payPerSecond; if (TotalBill > 0) { db.EmployeePayStubs.Add(new EmployeePayStub { CompanyId = company.CompanyId, EmployeeId = item.Key, PayCheck = TotalBill, PayDay = DateTime.Today }); } } db.SaveChanges(); return(RedirectToAction("Index")); }
public UserLoginTests() { // Arrange var options = new DbContextOptionsBuilder <TimeSheetDbContext>() .UseInMemoryDatabase(databaseName: "EmployeeDataBase") .Options; _ctx = new TimeSheetDbContext(options); _ctx.UserLogins.Add(new UserLogin { LoginTime = login1, UUId = "1" }); _ctx.UserLogouts.Add(new UserLogout { LogoutTime = logout1, UUId = "1" }); _ctx.UserLogins.Add(new UserLogin { LoginTime = login2, UUId = "1" }); _ctx.UserLogouts.Add(new UserLogout { LogoutTime = logout2, UUId = "1" }); _ctx.UserLogins.Add(new UserLogin { LoginTime = login3, UUId = "1" }); _ctx.UserLogouts.Add(new UserLogout { LogoutTime = logout3, UUId = "1" }); _ctx.SaveChanges(); _repo = new UserLoginRepository(_ctx); }
public ActionResult Create([Bind(Include = "EmployeeId,ProjectId,Date,Time")] WorkSchedule workSchedule) { if (ModelState.IsValid) { var project = db.Projects.FirstOrDefault(x => x.ProjectId == workSchedule.ProjectId); workSchedule.CompanyId = project.CompanyId; // db.WorkScheudules.Add(new WorkSchedule {ClientId=,CompanyId= }) db.WorkScheudules.Add(workSchedule); db.SaveChanges(); return(RedirectToAction("Index")); } var user = User.Identity.GetUserId(); var company = db.CompanyEmployees.SingleOrDefault(x => x.EmployeeId == user); // ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "ClientName", workSchedule.ClientId); ViewBag.EmployeeId = new SelectList(db.CompanyEmployees.Include("Employee").Where(x => x.CompanyId == company.CompanyId), "Id", "Employee.FullName"); ViewBag.ProjectId = new SelectList(db.Projects.Where(x => x.CompanyId == company.CompanyId), "ProjectId", "ProjectName"); return(View(workSchedule)); }
public ActionResult Create([Bind(Include = "RecieverId,Message")] Chat chat) { var user = User.Identity.GetUserId(); var company = db.CompanyEmployees.FirstOrDefault(x => x.EmployeeId == user); if (ModelState.IsValid) { chat.SenderId = user; chat.CompanyId = company.CompanyId; db.Chats.Add(chat); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RecieverId = new SelectList(db.CompanyEmployees.Include("Employee").Where(x => x.CompanyId == company.CompanyId), "EmployeeId", "Employee.FullName"); return(View(chat)); }
public ActionResult Create(Project project) { var user = User.Identity.GetUserId(); var company = db.CompanyEmployees.SingleOrDefault(x => x.EmployeeId == user); db.Projects.Add(new Project { CompanyId = company.CompanyId, ProjectName = project.ProjectName, IsCompleted = false, IsDeleted = false, IsForClient = false }); db.SaveChanges(); return(RedirectToAction("Index")); }