Esempio n. 1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (WAYNMngEntities context = CreateContext())
                {
                    WAYN dbItem = context.WAYN.FirstOrDefault(o => o.WAYNID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Data not found!");
                    }
                    context.WAYN.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data     = new List <DTO.WAYN>();
            data.FileScan = new DTO.FileScan();
            totalRows     = 0;

            //try to get data
            try
            {
                using (WAYNMngEntities context = CreateContext())
                {
                    var _data  = context.WAYNMng_WAYN_View.ToList();
                    var result = _data.GroupBy(x => x.WorkingDate).Select(grp => grp.First()).ToList();
                    totalRows = result.Count();
                    data.Data = converter.DB2DTO_WAYNList(result);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Esempio n. 3
0
        public bool DeleteList(int userId, object dtoItem, out Library.DTO.Notification notification)
        {
            List <DTO.EmployeeList> dtoEmployeeList = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.EmployeeList> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                foreach (DTO.EmployeeList dtoEmployee in dtoEmployeeList)
                {
                    using (WAYNMngEntities context = CreateContext())
                    {
                        WAYN dbItem = context.WAYN.FirstOrDefault(o => o.WAYNID == dtoEmployee.WAYNID);
                        if (dbItem == null)
                        {
                            throw new Exception("Employee not found !");
                        }

                        context.WAYN.Remove(dbItem);
                        context.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 4
0
        public IEnumerable <DTO.EmployeeList> GetDetail(int userId, string date, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            //Change to format dd-mm-yyy when testing on local
            DateTime _Date = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string   Date  = _Date.ToString("MM/dd/yyyy");

            try
            {
                using (WAYNMngEntities context = CreateContext())
                {
                    var data   = context.WAYNMng_EmployeeList_View.Where(o => o.WorkingDate == _Date);
                    var result = converter.DB2DTO_EmployeeList(data.ToList());
                    return(result);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(new List <DTO.EmployeeList>());
            }
        }
Esempio n. 5
0
        public bool UpdateNewList(int userId, object dtoItem, string date, out Library.DTO.Notification notification)
        {
            List <DTO.EmployeeList> dtoEmployeeList = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.EmployeeList> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            if (dtoEmployeeList != null)
            {
                try
                {
                    foreach (DTO.EmployeeList dtoEmployee in dtoEmployeeList)
                    {
                        using (WAYNMngEntities context = CreateContext())
                        {
                            WAYN dbItem = null;
                            dbItem = new WAYN();
                            context.WAYN.Add(dbItem);
                            dtoEmployee.WorkingDate = date;
                            converter.DTO2DB(dtoEmployee, ref dbItem);
                            LeaveRequest dbLeaveRequest = null;
                            dbLeaveRequest = new LeaveRequest();
                            dbLeaveRequest = context.LeaveRequest.FirstOrDefault(o => o.RequesterID == dbItem.EmployeeID);
                            if (dbLeaveRequest != null)
                            {
                                if (dbItem.WorkingDate >= dbLeaveRequest.FromDate && dbItem.WorkingDate <= dbLeaveRequest.ToDate)
                                {
                                    dbItem.IsOutOfOffice = true;
                                    dbItem.LeaveTypeID   = dbLeaveRequest.LeaveTypeID;
                                    if (dbLeaveRequest.TotalDays == (decimal)0.5)
                                    {
                                        dbItem.IsHaftDayOff = true;
                                    }
                                    dbItem.Description = dbLeaveRequest.ReasonForLeave;
                                }
                            }
                            dbItem.UpdatedBy   = userId;
                            dbItem.UpdatedDate = DateTime.Now;
                            context.SaveChanges();
                        }
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    notification.Type    = Library.DTO.NotificationType.Error;
                    notification.Message = ex.Message;
                    return(false);
                }
            }
            else
            {
                throw new Exception("Cannot find file location !");
            }
        }