Beispiel #1
0
        public IActionResult CancelPayment(int id)
        {
            try
            {
                Payment payment = context.Payment
                                  .Include(p => p.days)
                                  .Include(p => p.employee)
                                  .First(p => p.Id == id);
                foreach (Attendance atd in payment.days)
                {
                    atd.PaymentId = null;
                }

                context.Remove(payment);
                context.SaveChanges();

                TempData["msg"] = $"Pagesa për punëtorin {payment.employee.FirstName} {payment.employee.LastName} u anullua!";
                return(RedirectToAction("Payment", new { id = payment.employeeId }));
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }