示例#1
0
        private void DeletePaymentPeriodDetailed(int paymentPeriodId, int userId)
        {
            try
            {
                using (JakieKieszonkoweEntities db = new JakieKieszonkoweEntities())
                {
                    var isAdmin = db.Users.FirstOrDefault(i => i.Id_user == userId).IsAdmin;
                    if (!isAdmin)
                    {
                        throw new Exception("Nie posiadasz wystarczających uprawnień.");
                    }
                    Payout_period payoutPeriod = db.Payout_periods.FirstOrDefault(i => i.Id_payout_period == paymentPeriodId);

                    var children = db.Children.Where(i => i.Id_payout_period == paymentPeriodId).Include(i => i.Child_pocket_money_option);
                    foreach (var child in children)
                    {
                        db.Children.Remove(child);
                    }

                    db.Payout_periods.Remove(payoutPeriod);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
 private void EditPaymentPeriodDetailed(string paymentPeriodName, int days, int paymentPeriodId, int userId)
 {
     try
     {
         using (JakieKieszonkoweEntities db = new JakieKieszonkoweEntities())
         {
             var isAdmin = db.Users.FirstOrDefault(i => i.Id_user == userId).IsAdmin;
             if (!isAdmin)
             {
                 throw new Exception("Nie posiadasz wystarczających uprawnień.");
             }
             Payout_period payoutPeriod = db.Payout_periods.FirstOrDefault(i => i.Id_payout_period == paymentPeriodId);
             payoutPeriod.Name = paymentPeriodName;
             payoutPeriod.Days = days;
             db.Payout_periods.Attach(payoutPeriod);
             db.Entry(payoutPeriod).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }