public ActionResult Create([Bind(Include = "SectorName,SectionID")] Sector sector) { try { if (ModelState.IsValid) { if (!(String.IsNullOrEmpty(sector.SectorName) || db.chkSectorNameExist(sector.SectorName))) { db.Sectors.Add(sector); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.ErrorValidation = String.IsNullOrEmpty(sector.SectorName) ? "You have not entered a value for Sector" : $"There already exist a Sector named \"{sector.SectorName}\""; } } } catch (Exception ex) { ViewBag.ErrorValidation = $"An error occured while creating this Sector \n{ex.Message}"; } return(View(sector)); }
public ActionResult Create([Bind(Include = "CodeID,CodeDescription,CodeValue")] HourCode hourCode) { if (ModelState.IsValid) { db.HourCodes.Add(hourCode); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hourCode)); }
public ActionResult Create([Bind(Include = "id_Employee,id_contractor,FirstName,LastName,PhoneNumber,EmailAdress,CreatedAt,LastModifiedAt,DeletedAt,Active")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.id_contractor = new SelectList(db.Contractors, "id_Contractor", "CompanyName", employee.id_contractor); return(View(employee)); }
public ActionResult Create([Bind(Include = "id_WorkAssignment,id_Customer,Title,Description,Deadline,InProsess,InProgressAt,Completed,CompletedAt,CreatedAt,LastModifiedAt,DeletedAt,Active")] WorkAssignment workAssignment) { if (ModelState.IsValid) { db.WorkAssignments.Add(workAssignment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.id_Customer = new SelectList(db.Customers, "id_Customer", "CustomerName", workAssignment.id_Customer); return(View(workAssignment)); }
public ActionResult Create([Bind(Include = "UserID,FirstName,LastName,Email,Phone,JobDescription,Password,confirmPassword,JobRoleID")] User user) { if (ModelState.IsValid) { //Hashing password user.Password = Crypto.Hash(user.Password); //Hash confirm password user.confirmPassword = Crypto.Hash(user.confirmPassword); db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.JobRoleID = new SelectList(db.Job_Role, "JobRoleID", "JobDescription", user.JobRoleID); return(View(user)); }
public JsonResult SaveRecord(Timesheet t) { var status = false; using (TimesheetEntities dc = new TimesheetEntities()) { if (t.TimesheetID > 0) { var v = dc.Timesheets.Where(a => a.TimesheetID == t.TimesheetID).FirstOrDefault(); if (v != null) { v.ChangeDate = t.ChangeDate; v.User = t.User; v.Start = t.Start; v.End = t.End; v.Description = t.Description; } } else { dc.Timesheets.Add(t); } dc.SaveChanges(); status = true; } return(new JsonResult { Data = new { status = status } }); }
public ActionResult Create([Bind(Include = "JobRoleID,JobDescription")] Job_Role job_Role) { if (ModelState.IsValid) { db.Job_Role.Add(job_Role); db.SaveChanges(); return(RedirectToAction("Index")); } else if (job_Role == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { return(View(job_Role)); } }
public ActionResult Create([Bind(Include = "LocationID,HourCodeId")] Schedule schedule, FormCollection data) { int hi = Convert.ToInt32(data["HourCodeId"]); HourCode hr = db.HourCodes.Single(emp => emp.CodeID == hi); string timein = data["Date"] + " " + data["Time_In"]; string timeout = data["Date"] + " " + data["Time_Out"]; schedule.Time_In = DateTime.ParseExact(timein, "yyyy-MM-dd HH:mm", null); schedule.Time_Out = DateTime.ParseExact(timeout, "yyyy-MM-dd HH:mm", null); schedule.DoctorID = Convert.ToInt32(TempData["DoctorID"]); schedule.Amount = hr.CodeValue; if (ModelState.IsValid) { db.Schedules.Add(schedule); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DoctorID = new SelectList(db.Doctors, "DoctorId", "FirstName", schedule.DoctorID); ViewBag.LocationID = new SelectList(db.Locations, "LocationId", "LocationName", schedule.LocationID); ViewBag.HourCodeId = new SelectList(db.HourCodes, "CodeID", "CodeID", schedule.HourCodeId); return(View(schedule)); }
public ActionResult Create([Bind(Include = "LocationID,LocationName,SectionID")] Location location) { try { ViewBag.strSlectedSector = location.SectionID; if (ModelState.IsValid) { if (!String.IsNullOrEmpty(location.LocationName)) { if (!(String.IsNullOrEmpty(location.LocationName) || db.chkLocationNameExist(location.LocationName))) { db.Locations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.ValLocationName = String.IsNullOrEmpty(location.LocationName) ? "You have not entered a value for Location" : $"There already exist a Location named \"{location.LocationName}\""; } } else { ViewBag.ValSectorName = "Select a value for Sector Name"; } } ViewBag.SectionID = new SelectList(db.Sectors, "SectionID", "SectorName", location.SectionID); } catch (Exception ex) { ViewBag.SectionID = new SelectList(db.Sectors, "SectionID", "SectorName", location.SectionID); ViewBag.ValSummary = $"An error occured while creating this Location \n{ex.Message}"; } return(View(location)); }
public JsonResult DeleteRecord(int recID) { var status = false; using (TimesheetEntities dc = new TimesheetEntities()) { var v = dc.Timesheets.Where(a => a.TimesheetID == recID).FirstOrDefault(); if (v != null) { dc.Timesheets.Remove(v); dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
public bool PostStatus(FotoModel input)//, string Name, byte[]FotoData) { TimesheetEntities entities = new TimesheetEntities(); try { string[] nameParts = input.Name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string first = nameParts[0]; string last = nameParts[1]; Employee existing = (from ts in entities.Employees where (ts.FirstName == first) && (ts.LastName == last) select ts).FirstOrDefault(); if (existing != null) { existing.EmployeePicture = input.Fotodata; } else { return(false); } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public string PutEmployeeImage() { TimesheetEntities entities = new TimesheetEntities(); try { Employee newEmployee = new Employee() { FirstName = "Heebo", LastName = "X", EmployeePicture = File.ReadAllBytes(@"C:\Users\maria\Koodit\Heebo.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } }
public string PutEmployeeImage() { TimesheetEntities entities = new TimesheetEntities(); try { Employee newEmployee = new Employee() { FirstName = "Aaro", LastName = "aalto", EmployeePicture = System.IO.File.ReadAllBytes(@"C:\Temp\Heebo.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } //return "Error"; }
public bool PostStatus(WorkAssignmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { WorkAssignments assignment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assignment == null) { return(false); } if (input.Operation == "Start") { int assignmentId = assignment.Id_WorkAssignment; Timesheets newEntry = new Timesheets() { Id_WorkAssignment = assignmentId, StartTime = DateTime.Now, WorkComplete = false, Active = true, CreatedAt = DateTime.Now }; entities.Timesheets.Add(newEntry); //Päivitetään samalla work-assignmentin tilatietoja assignment.InProgress = true; assignment.InProgressAt = DateTime.Now; assignment.LastModifiedAt = DateTime.Now; } else if (input.Operation == "Stop") { int assignmentId = assignment.Id_WorkAssignment; Timesheets existing = (from ts in entities.Timesheets where (ts.Id_WorkAssignment == assignmentId) && (ts.Active == true) && (ts.WorkComplete == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkComplete = true; existing.LastModifiedAt = DateTime.Now; //Päivitetään samalla work-assignmentin tilatietoja assignment.InProgress = false; assignment.Completed = true; assignment.CompletedAt = DateTime.Now; assignment.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostStatus(WorkAssigmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { //Jos olisi lista List<string> alkuun ja ToArrayn tilaalle ToLista(); WorkAssignment assingnment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assingnment == null) { return(false); } if (input.Operation == "Start") { int assignmentid = assingnment.Id_WorkAssignment; Timesheet newEntry = new Timesheet() { id_WorkAssignment = assignmentid, StartTime = DateTime.Now, WorkCompleted = false, Active = true, CreatedAt = DateTime.Now }; entities.Timesheets.Add(newEntry); } else if (input.Operation == "Stop") { int assignmentid = assingnment.Id_WorkAssignment; Timesheet existing = (from ts in entities.Timesheets where (ts.id_WorkAssignment == assignmentid) && (ts.Active == true) && (ts.WorkCompleted == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkCompleted = true; existing.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostStatus(WorkAssignmentOperationModel input) { TimesheetEntities entities = new TimesheetEntities(); try { WorkAssignment assignment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assignment == null) { return(false); } //string value; //decimal number; NumberStyles style; CultureInfo provider; provider = new CultureInfo("fi-FI"); string valueString = input.Latitude.ToString("R", CultureInfo.InvariantCulture); style = NumberStyles.AllowDecimalPoint; if (input.Operation == "Start") { int assignmentId = assignment.id_WorkAssignment; Timesheet newEntry = new Timesheet() { id_WorkAssignment = assignmentId, StartTime = DateTime.Now, WorkComplete = false, Active = true, CreatedAt = DateTime.Now, Latitude = Convert.ToDecimal(input.Latitude), Longitude = Convert.ToDecimal(input.Longitude) }; entities.Timesheets.Add(newEntry); } else if (input.Operation == "Stop") { int assignmentId = assignment.id_WorkAssignment; Timesheet existing = (from ts in entities.Timesheets where (ts.id_WorkAssignment == assignmentId) && (ts.Active == true) && (ts.WorkComplete == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkComplete = true; existing.LastModifiedAt = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public void CommitAndDispose() { db.SaveChanges(); db.Dispose(); }