public ActionResult UpdateStageSeq(Stage stage, string seq) { using (var _db = new HRMSContext()) { //update all sequence value to 0 string[] sq = seq.Split(','); foreach (var item in sq) { int q = Convert.ToInt32(item); Stage s = _db.Stages.SingleOrDefault(i => i.StageID == q); s.Seq = 0; _db.SaveChanges(); } foreach (var item in sq) { int q = Convert.ToInt32(item); Stage s = _db.Stages.SingleOrDefault(i => i.StageID == q); //get last sequence var idKey = (from c in _db.Stages // the table1 here has red line under it. orderby c.Seq descending select c).First(); int last = idKey.Seq; s.Seq = last + 1; _db.SaveChanges(); } } //update seq field to 1,2,3... so on and so forth return(RedirectToAction("Stage")); }
public ActionResult StageForm(Stage stage) { try { using (var context = new HRMSContext()) { context.Stages.Add(stage); context.SaveChanges(); //get last sequence var idKey = (from c in context.Stages // the table1 here has red line under it. orderby c.Seq descending select c).First(); int last = idKey.Seq; Stage s = _db.Stages.SingleOrDefault(i => i.StageID == stage.StageID); s.Seq = last + 1; _db.SaveChanges(); } TempData["color"] = "green"; TempData["result"] = "Successfully Saved New Stage Record Database."; } catch (Exception ex) { TempData["color"] = "red"; TempData["result"] = ex.Message; } return(RedirectToAction("Stage")); }
public ActionResult Create(Candidate candidate) { try { using (var context = new HRMSContext()) { candidate.CreatedDate = DateTime.Now; context.Candidates.Add(candidate); context.SaveChanges(); //upload candidate's resume //drops database and data with it //Database.SetInitializer<CandidateContext>(new DropCreateDatabaseAlways<CandidateContext>()); if (Request.Files["cvfile"].ContentLength > 0) { //get last insert id for saving the resume string filename = candidate.Firstname + "_" + candidate.Lastname + "_" + candidate.CandidateID; string extension = System.IO.Path.GetExtension(Request.Files["cvfile"].FileName); string path = string.Format("{0}/{1}{2}", Server.MapPath("~/Documents/cv"), filename, extension); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } Request.Files["cvfile"].SaveAs(path); Candidate c = _db.Candidates.SingleOrDefault(i => i.CandidateID == candidate.CandidateID); c.CVFilename = filename; _db.SaveChanges(); } else { candidate.CVFilename = ""; } } TempData["color"] = "green"; TempData["result"] = "Successfully Saved New Candidate To Database."; return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Alert = ex.Message; return(View()); } }
public IActionResult Save(AddTimeSheet items, [FromQuery] string save) { //Module items = itemsData.Data; //var itemsObject = await request.Content.; //AddTimeSheet items = JsonConvert.DeserializeObject<AddTimeSheet>(request); try { Timesheetv2 timeSheet = new Timesheetv2(); var existingEmployeee = db.Timesheetv2.FirstOrDefault(item => items.empId == item.EmpId); if (existingEmployeee == null) { timeSheet.EmpId = items.empId; timeSheet.EmpName = items.empName; db.Add(timeSheet); db.SaveChanges(); } foreach (TimeSheetData value in items.Data) { Timesheetitemv2 timeSheetItem = new Timesheetitemv2(); Timesheetentryv2 timeSheetEntry = new Timesheetentryv2(); timeSheetItem.Hours = value.hours; timeSheetItem.EmpId = items.empId; timeSheetItem.Status = save; timeSheetItem.Submittedto = value.submittedto; timeSheetItem.ToDate = items.toDate; timeSheetItem.FromDate = items.fromDate; timeSheetItem.Date = value.date; db.Add(timeSheetItem); db.SaveChanges(); int index = timeSheetItem.TimestampId; timeSheetEntry.Customer = value.customer; timeSheetEntry.Company = value.company; timeSheetEntry.Task = value.task; timeSheetEntry.Project = value.project; timeSheetEntry.Timestampid = index; db.Add(timeSheetEntry); db.SaveChanges(); } return(Ok(new { value = 200 })); } catch (Exception e) { Console.Write(e); var s = e; return(BadRequest(new { error = e })); } }
public IActionResult ApproveOrReject([FromQuery] string empid, DateTime fromDate, string option) { try { if (option == "approve") { List <Timesheetitemv2> list = (from p in db.Timesheetitemv2 where ((p.EmpId == empid) && (p.FromDate == fromDate)) select p).ToList(); foreach (Timesheetitemv2 item in list) { item.Status = "approved"; } db.SaveChanges(); return(Ok(new { statusCode = 200, message = "done", })); } else { List <Timesheetitemv2> list = (from p in db.Timesheetitemv2 where ((p.EmpId == empid) && (p.FromDate == fromDate)) select p).ToList(); foreach (Timesheetitemv2 item in list) { item.Status = "rejected"; } db.SaveChanges(); db.SaveChanges(); return(Ok(new { statusCode = 200, message = "done", })); } } catch (Exception e) { return(BadRequest(new { statusCode = 400, message = "Error", data = "string", })); } }
//[Authorize] public IActionResult Post([FromForm] addvalue value) { TimeSheet timeSheet = new TimeSheet(); TimeSheetItem timeSheetItem = new TimeSheetItem(); TimeSheetEntry timeSheetEntry = new TimeSheetEntry(); try { //TimeSheet obj = JsonConvert.DeserializeObject<TimeSheet>(value); timeSheet.EmpId = value.EmpId; timeSheetItem.Hours = value.Hours; timeSheetItem.EmpId = value.EmpId; timeSheetEntry.Customer = value.Customer; timeSheetEntry.Company = value.Company; timeSheetEntry.Task = value.Task; timeSheetEntry.Project = value.Project; timeSheetEntry.EmpId = value.EmpId; timeSheetEntry.Status = "pending"; timeSheetItem.Date = "null"; timeSheetItem.From = "null"; timeSheetItem.To = "null"; timeSheet.EmployeeName = "null"; timeSheetEntry.EmployeeName = timeSheet.EmployeeName; timeSheet.Id = 1; timeSheetEntry.Id = timeSheet.Id; timeSheetItem.Id = 1; db.TimeSheet.Add(timeSheet); db.TimeSheetItem.Add(timeSheetItem); db.TimeSheetEntry.Add(timeSheetEntry); db.SaveChanges(); return(Ok(new { StatusCode = 200, Message = "done", // data = q })); } catch (Exception e) { Console.WriteLine(e); return(Ok(new { StatusCode = 500, Message = "unauthorized" })); } }
// PUT: odata/JobPosteds(5) public IHttpActionResult Put([FromODataUri] int key, Delta <JobPosted> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } JobPosted jobPosted = db.JobPosteds.Find(key); if (jobPosted == null) { return(NotFound()); } patch.Put(jobPosted); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JobPostedExists(key)) { return(NotFound()); } else { throw; } } return(Updated(jobPosted)); }
// PUT: odata/EmployeeLogins(5) public IHttpActionResult Put([FromODataUri] int key, Delta <EmployeeLogin> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } EmployeeLogin employeeLogin = db.EmployeeLogins.Find(key); if (employeeLogin == null) { return(NotFound()); } patch.Put(employeeLogin); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeLoginExists(key)) { return(NotFound()); } else { throw; } } return(Updated(employeeLogin)); }
// PUT: odata/SalaryDetails(5) public IHttpActionResult Put([FromODataUri] int key, Delta <SalaryDetail> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SalaryDetail salaryDetail = db.SalaryDetails.Find(key); if (salaryDetail == null) { return(NotFound()); } patch.Put(salaryDetail); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SalaryDetailExists(key)) { return(NotFound()); } else { throw; } } return(Updated(salaryDetail)); }
public ActionResult Update(Candidate candidate, int id) { using (var _db = new HRMSContext()) { Candidate c = _db.Candidates.SingleOrDefault(i => i.CandidateID == id); c.Firstname = candidate.Firstname; c.Lastname = candidate.Lastname; c.Title = candidate.Title; c.Email = candidate.Email; c.Telephone = candidate.Telephone; c.Status = candidate.Status; c.ShortDesc = candidate.ShortDesc; if (Request.Files["cvfile"].ContentLength > 0) { //get last insert id for saving the resume string filename = candidate.Firstname + "_" + candidate.Lastname + "_" + id; string extension = System.IO.Path.GetExtension(Request.Files["cvfile"].FileName); string path = string.Format("{0}/{1}{2}", Server.MapPath("~/Documents/cv"), filename, extension); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } Request.Files["cvfile"].SaveAs(path); candidate.CVFilename = filename + "." + extension; } else { candidate.CVFilename = ""; } c.CVFilename = candidate.CVFilename; _db.SaveChanges(); TempData["color"] = "green"; TempData["result"] = "Successfully Updated Candidate Record."; } return(RedirectToAction("Index")); }
public ActionResult Create(Opening opening) { try { using (var context = new HRMSContext()) { opening.CreatedDate = DateTime.Now; context.Openings.Add(opening); context.SaveChanges(); } } catch (Exception ex) { TempData["color"] = "red"; TempData["result"] = ex.Message; } return(new RedirectResult(Url.Action("Hire", new { id = opening.OpeningID }) + "?#tabs-2")); }
public ActionResult UpdateStage(Stage stage, int id) { using (var _db = new HRMSContext()) { Stage s = _db.Stages.SingleOrDefault(i => i.StageID == id); //get last sequence var idKey = (from c in _db.Stages // the table1 here has red line under it. orderby c.Seq descending select c).First(); int last = idKey.Seq; s.Desc = stage.Desc; _db.SaveChanges(); TempData["color"] = "green"; TempData["result"] = "Successfully Updated Candidate Record."; } return(RedirectToAction("Stage")); }