コード例 #1
0
        public dynamic PutVacation(VacationOrderPVM p)
        {
            var vacation = db.Vacations_Orders.Find(p.vacationId);

            //check before update if this order active and it's time pass
            //if (vacation.OrderStatusId == 4 && vacation.From_Date < DateTime.Now)
            //{
            //    return new { result = " غير مسموح بتعديل فى اجازة تمت" };
            //}

            //check if this vacation taked action on it
            if (vacation.OrderStatusId != (int)OrderStatus.Order)
            {
                return(new { result = "  غير مسموح بتعديل فى اجازة تم اخذ القرار فيها " });
            }



            //select this vacation type
            var vacationType = db.Vacations_Types.Where(m => m.VacationType_ID == p.vacationTypeId).FirstOrDefault();

            //select the previous vacation for this vacation type for this employee in this year and count days
            var takedVacations = db.Vacations_Orders.
                                 Where(b => b.VacationType_ID == p.vacationTypeId && b.Employee_ID == p.employeeId && b.Year_ID == p.yearId && b.OrderStatusId == (int)OrderStatus.AcceptedByHr).ToList();


            //select this employee
            var Emp = db.Employees.Where(f => f.Employee_ID == p.employeeId).FirstOrDefault();


            //تحديد عدد ايام الاجازة
            TimeSpan timeSpan        = p.toDate.Date - p.fromDate.Date;
            int      orderdays_Count = Convert.ToInt32(timeSpan.TotalDays);


            //check if this employee have vacation days to take it or not
            if (orderdays_Count > (vacationType.Max_Days - (takedVacations.Sum(v => v.count)) + vacation.count))
            {
                return(new { result = " تخطى عدد الايام المسموح" });
            }

            //check if this employee finished the permitted monthes from him assignment date to take this vacation
            if (vacationType.Reg_Max_Month > 0)
            {
                //للتحديد عدد الشهورر بداية من تعيينه
                TimeSpan timeSpan2         = p.fromDate.Date - Emp.Assigment_Date.Value.Date;
                int      assignmentMonthes = Convert.ToInt32(timeSpan2.TotalDays) / 30;

                if (assignmentMonthes < vacationType.Reg_Max_Month)
                {
                    return(new { result = "لم يتخطى المدة المطلوبة منذ تعينه لاخذ الاجازة" });
                }
            }

            //check if this employee finished the permitted dayes in this month or not
            if (vacationType.Month_Max_Times != 0)
            {
                if (
                    (
                        (takedVacations.Where(m => m.Month_ID == p.monthId).Sum(v => v.count))
                        + orderdays_Count) > vacationType.Month_Max_Times)
                {
                    return(new { result = "تخطى عدد الايام المسموح بها للاجازة " + vacationType.Type_Name + " خلال الشهر!!" });
                }
            }

            //check first if this type of vacations demand spicific period and then if demand then check if the order period in it or no
            if (vacationType.With_Period == true)
            {
                if (p.fromDate.Date > vacationType.To_Date)
                {
                    return(new { result = "خارج الفترة الزمنية لهذا النوع من الاجازة" });
                }
            }


            //vacation.Order_Date = DateTime.Now;
            vacation.VacationType_ID = p.vacationTypeId;
            vacation.Employee_ID     = p.employeeId;
            vacation.From_Date       = p.fromDate.Date;
            vacation.To_Date         = p.toDate.Date;
            vacation.OrderStatusId   = Convert.ToInt32(OrderStatus.Order);
            vacation.Month_ID        = p.monthId;
            vacation.Year_ID         = p.yearId;
            vacation.Vacation_Notes  = p.vacationNotes;
            vacation.count           = Convert.ToByte(orderdays_Count);
            vacation.User_ID         = p.userId;
            vacation.Last_Update     = DateTime.Now;

            var result = db.SaveChanges() > 0 ? true : false;

            return(new
            {
                result = result
            });
        }
コード例 #2
0
        public dynamic PostVacation(VacationOrderPVM p)
        {
            //select this vacation type
            var vacationType = db.Vacations_Types.Where(m => m.VacationType_ID == p.vacationTypeId).FirstOrDefault();

            //select the previous vacation for this vacation type for this employee in this year and count days
            var takedVacations = db.Vacations_Orders.
                                 Where(b => b.VacationType_ID == p.vacationTypeId && b.Employee_ID == p.employeeId && b.Year_ID == p.yearId && b.OrderStatusId == (int)OrderStatus.AcceptedByHr).ToList();


            //select this employee
            var Emp = db.Employees.Where(f => f.Employee_ID == p.employeeId).FirstOrDefault();


            //تحديد عدد ايام الاجازة
            TimeSpan timeSpan        = p.toDate.Date - p.fromDate.Date;
            int      orderdays_Count = Convert.ToInt32(timeSpan.TotalDays);


            //check if this employee have vacation days to take it or not
            if (orderdays_Count > (vacationType.Max_Days - (takedVacations.Sum(v => v.count))))
            {
                return(new { result = " تخطى عدد الايام المسموح" });
            }

            //check if this employee finished the permitted monthes from him assignment date to take this vacation
            if (vacationType.Reg_Max_Month > 0)
            {
                //للتحديد عدد الشهورر بداية من تعيينه
                TimeSpan timeSpan2         = p.fromDate.Date - Emp.Assigment_Date.Value;
                int      assignmentMonthes = Convert.ToInt32(timeSpan2.TotalDays) / 30;

                if (assignmentMonthes < vacationType.Reg_Max_Month)
                {
                    return(new { result = "لم يتخطى المدة المطلوبة منذ تعينه لاخذ الاجازة" });
                }
            }

            //check if this employee finished the permitted dayes in this month or not
            if (vacationType.Month_Max_Times != 0)
            {
                if (((takedVacations.Where(m => m.Month_ID == p.monthId).Sum(v => v.count)) + orderdays_Count) > vacationType.Month_Max_Times)
                {
                    return(new { result = "تخطى عدد الايام المسموح بها للاجازة " + vacationType.Type_Name + " خلال الشهر!!" });
                }
            }


            //check first if this type of vacations demand spicific period and then if demand then check if the order period in it or no
            if (vacationType.With_Period == true)
            {
                if (p.fromDate.Date > vacationType.To_Date)
                {
                    return(new { result = "خارج الفترة الزمنية لهذا النوع من الاجازة" });
                }
            }

            //if (vacationsType.For_Emp_Type == false || (vacationsType.For_Emp_Type == true && vacationsType.Emp_Type == g.Category_ID))
            //or from list of available vacation types


            var vacationOrder = db.Vacations_Orders.Add(new Vacations_Orders
            {
                Order_Date      = DateTime.Now,
                VacationType_ID = p.vacationTypeId,
                Employee_ID     = p.employeeId,
                From_Date       = p.fromDate.Date,
                To_Date         = p.toDate.Date,
                OrderStatusId   = Convert.ToInt32(OrderStatus.Order),
                Month_ID        = p.monthId,
                Year_ID         = p.yearId,
                Vacation_Notes  = p.vacationNotes,
                count           = Convert.ToByte(orderdays_Count),
                User_ID         = p.userId,
                Last_Update     = DateTime.Now
            });
            var result = db.SaveChanges() > 0 ? true : false;

            return(new
            {
                result = result,
                vacationOrderId = vacationOrder.Order_ID
            });
        }