public JsonResult Create(string loan) { try { if (ModelState.IsValid) { Loan loanObj = JsonConvert.DeserializeObject <Loan>(loan); loanObj.CreatedBy = "admin"; loanObj.CreatedDate = DateTime.Now; loanObj.LastUpdBy = "admin"; loanObj.LastUpdDate = DateTime.Now; loanObj.CompanyId = "ABC"; // TODO: Add update logic here //_context.Update(user); _context.Add(loanObj); _context.SaveChanges(); } return(Json(new { Success = true })); } catch { throw; } }
public async Task <IActionResult> Create([Bind("AssistanceLogId,Date,EmployeeId")] AssistanceLog assistanceLog) { try { if (ModelState.IsValid) { assistanceLog.Date = assistanceLog.Date.Date; _context.Add(assistanceLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "Name", assistanceLog.EmployeeId); return(View(assistanceLog)); } catch (Exception ex) { ViewBag.ErrorMessage = ex.InnerException.Message.ToString(); var payrollContext = _context.AssistanceLog .Include(a => a.Employee) .Where(a => a.Date.Date >= DateTime.Today.AddDays(-14).Date); return(View(nameof(Index), await payrollContext.ToListAsync())); } }
public async Task <IActionResult> AddOrEdit(int id, [Bind("TransactionLogId,Date,ProductId,OperationId,BoxQty")] TransactionLog transactionLog) { TransactionLog exObj = new TransactionLog(); try { if (ModelState.IsValid) { transactionLog.Date = transactionLog.Date.Date; exObj = transactionLog; if (id == 0) { _context.Add(transactionLog); await _context.SaveChangesAsync(); } else { try { _context.Update(transactionLog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionLogExists(transactionLog.TransactionLogId)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.TransacionLog.Include(t => t.Operation).Include(t => t.Product) .Where(t => t.Date.Date >= DateTime.Today.AddDays(-14)).ToList()) })); } ViewData["OperationId"] = new SelectList(_context.Operation, "OperationId", "OperationName", transactionLog.OperationId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", transactionLog.ProductId); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", transactionLog) })); } catch (Exception ex) { ViewBag.ErrorMessage = ex.InnerException.Message.ToString(); ViewData["OperationId"] = new SelectList(_context.Operation, "OperationId", "OperationName", exObj.OperationId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", exObj.ProductId); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", exObj) })); } }
public async Task <IActionResult> Create([Bind("ID,Employer,HourlyRate")] Contract contract) { if (ModelState.IsValid) { _context.Add(contract); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contract)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,RateOfPay,HoursWorked,PayWeek")] Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Create([Bind("Id,EmployeeId,FirstName,LastName,Relationship")] Dependent dependent) { if (ModelState.IsValid) { _context.Add(dependent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), "Employees", new { id = dependent.EmployeeId })); } return(View(dependent)); }
public async Task <IActionResult> Create([Bind("OwnerId,ID,Status,totalHoursWorked,totalEarnings")] Payslip payslip) { if (ModelState.IsValid) { _context.Add(payslip); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(payslip)); }
public void AddDefaultData() { var emps = _context.Employees; if (emps.Count() == 0) { _context.Add(new Employee() { AnnualSalary = 60500, FirstName = "Christopher", LastName = "Tso" }); _context.Add(new Employee() { AnnualSalary = 70000, FirstName = "Jennifer", LastName = "Lopez" }); } _context.SaveChanges(); }
public JsonResult CreateDependents(string dependents) { try { if (ModelState.IsValid) { Dependents dependentsObj = JsonConvert.DeserializeObject <Dependents>(dependents); dependentsObj.CompanyId = HttpContext.Session.GetString("CompanyId"); _context.Add(dependentsObj); _context.SaveChanges(); } return(Json(new { Success = true })); } catch (Exception) { throw; } }
public async Task <IActionResult> Create([Bind("Mon,Tue,Wed,Thur,Fri,Sat,Sun,ID,Status,HoursWorked")] Timesheet timesheet) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { timesheet.OwnerId = currentUser.Id; timesheet.HoursWorked = timesheet.Mon + timesheet.Tue + timesheet.Wed + timesheet.Thur + timesheet.Fri + timesheet.Sat + timesheet.Sun; _context.Add(timesheet); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(timesheet)); }
public void Add <T>(T entity) where T : class { _db.Add(entity); }