Esempio n. 1
0
        public override DTO.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data              = new DTO.LeaveRequest();
            data.LeaveTypes        = new List <Module.Support.DTO.LeaveType>();
            data.LeaveRequestTimes = new List <Module.Support.DTO.LeaveRequestTime>();
            data.Managers          = new List <DTO.Manager>();
            data.Directors         = new List <DTO.Director>();

            //try to get data
            try
            {
                if (id > 0)
                {
                    using (LeaveRequestMngEntities context = CreateContext())
                    {
                        var LeaveRequest = context.LeaveRequestMng_LeaveRequest_View.FirstOrDefault(o => o.LeaveRequestID == id);
                        if (LeaveRequest == null)
                        {
                            throw new Exception("Can not found the LeaveRequest to edit");
                        }
                        data.Data = converter.DB2DTO_LeaveRequest(LeaveRequest);
                    }
                }
                data.LeaveTypes        = supportFactory.GetLeaveType().ToList();
                data.LeaveRequestTimes = supportFactory.GetLeaveRequestTime().ToList();
                data.Managers          = GetListManager().ToList();
                data.Directors         = GetListDirector().ToList();
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }