コード例 #1
0
ファイル: LeavePlan.cs プロジェクト: vinaykasireddy/ATSVINAY
        public static LeavePlan Save(LeavePlan leavePlan)
        {
            string result = string.Empty;

            try
            {
                ATSCEEntities context = new ATSCEEntities();
                if (leavePlan.LeavePlanId <= 0)
                {
                    context.LeavePlans.Add(leavePlan);
                }
                else
                {
                    context.Entry(leavePlan).State = System.Data.EntityState.Modified;
                }
                int rowAffected = context.SaveChanges();

                if (rowAffected <= 0)
                {
                    result = "Record is not saved";
                }
                return(leavePlan);
            }
            catch (Exception ex)
            {
                throw new Exception("Record is not saved [" + ex.Message + "]");
            }
        }
コード例 #2
0
ファイル: LeavePlan.cs プロジェクト: vinaykasireddy/ATSVINAY
 public static bool Delete(int leavePlanId)
 {
     try
     {
         ATSCEEntities context   = new ATSCEEntities();
         LeavePlan     leaveplan = context.LeavePlans.Find(leavePlanId);
         context.LeavePlans.Remove(leaveplan);
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #3
0
ファイル: LeavePlan.cs プロジェクト: vinaykasireddy/ATSVINAY
        public static IEnumerable <LeavePlan> AdmitOrRejectLeaves(int LeavePlanId, bool AdmitReject)
        {
            ATSCEEntities context       = new ATSCEEntities();
            LeavePlan     leaveToUpdate = context.LeavePlans.Where(lp => lp.LeavePlanId == LeavePlanId).FirstOrDefault();

            if (AdmitReject)
            {
                leaveToUpdate.Admitted = true;
            }
            else
            {
                leaveToUpdate.Admitted = false;
            }
            try
            {
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not admit or reject [" + ex.Message + "]");
            }

            return(GetAllLeavePlansBySupervisorId(int.Parse((leaveToUpdate.Person as Staff).SupervisorId.ToString())));
        }