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 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. 3
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 !");
            }
        }
Esempio n. 4
0
 public void DTO2DB(DTO.EmployeeList dtoItem, ref WAYN dbItem)
 {
     AutoMapper.Mapper.Map <DTO.EmployeeList, WAYN>(dtoItem, dbItem);
     dbItem.WorkingDate = dtoItem.WorkingDate.ConvertStringToDateTime();
 }