public IResponse StartWork(int resourceId)
        {
            var selectedAttendance = UOW.Attendances.SingleOrDefault(r => r.CreatedById == resourceId && r.EndWorkDate == null);

            if (selectedAttendance == null)
            {
                var newAttendance = new Attendance()
                {
                    CreatedById = resourceId, StartWorkDate = DateTime.Now
                };
                UOW.Attendances.Add(newAttendance);
                UOW.Compelete();
                var(data, rows) = UOW.Attendances.AttendanceFilter(new AttendanceSearchModel {
                    attendanceIds = new List <int> {
                        newAttendance.Id
                    }
                });
                response.data = data;
            }
            else
            {
                var(data, rows) = UOW.Attendances.AttendanceFilter(new AttendanceSearchModel {
                    attendanceIds = new List <int> {
                        selectedAttendance.Id
                    }
                });
                response.data = data;
            }
            return(response);
        }
        public IResponse TicketRequest(TicketRequestModel ticketRequest, int VisitorId)
        {
            var ServerDateTime = DateTime.Now.AddServerTimeHours();
            var TimeOfNow      = ServerDateTime.TimeOfDay;
            var DateOfNow      = ServerDateTime.Date;

            var selectedBranchDepartement = UOW.BranchDepartement.SingleOrDefault(bd => bd.BranchId == ticketRequest.BranchId &&
                                                                                  bd.DepartementId == ticketRequest.DepartementId);

            var(StartReservationTime, EndReservationTime) = GetBranchTime(ticketRequest.BranchId);

            if (StartReservationTime > TimeOfNow || EndReservationTime < TimeOfNow)
            {
                response.status   = false;
                response.error_AR = "لا يمكن الحجز في هذا الموعد";
                response.error_EN = "Time not available for Reservation";
                response.data     = null;
                return(response);
            }


            //CHECK IF HAS TICKET BEFORE
            var SelectedTicket = UOW.Tickets.FirstOrDefault(t => t.BranchDepartementId == selectedBranchDepartement.Id &&
                                                            t.CreatedById == VisitorId && t.StatusId != 3 && t.CreatedAt.Date == DateOfNow);

            if (SelectedTicket != null)
            {
                response.status   = false;
                response.error_AR = "يوجد حجز مسبق في نفس اليوم";
                response.error_EN = "There is already ticket Requested";
                response.data     = VisitorDailyTickets(new TicketVisitorSearchModel()
                {
                    ticketIds = { SelectedTicket.Id }, visitorId = SelectedTicket.CreatedById.Value
                }).data;
                return(response);
            }

            var CurrentNumber = UOW.Tickets.Find(t => t.BranchDepartementId == selectedBranchDepartement.Id &&
                                                 t.CreatedAt.Date == DateOfNow)
                                .Select(t => t.TicketNumber).DefaultIfEmpty(0).Max();
            var newTicket = new Ticket();

            newTicket.TicketNumber        = CurrentNumber + 1;
            newTicket.CreatedById         = VisitorId;
            newTicket.BranchDepartementId = selectedBranchDepartement.Id;
            newTicket.StatusId            = 1;
            UOW.Tickets.Add(newTicket);
            UOW.Compelete();
            #region notification
            notification.NotifyNewEvent("E_NewTicket" + newTicket.BranchDepartementId,
                                        new { newTicket.Id, newTicket.TicketNumber, newTicket.CreatedById.Value });
            #endregion
            //Notification Employees
            response.data = VisitorDailyTickets(new TicketVisitorSearchModel()
            {
                ticketIds = { newTicket.Id }, visitorId = newTicket.CreatedById.Value
            }).data;
            return(response);
        }
Exemple #3
0
        public IRequestResult Create(CreateItem model)
        {
            Item item = mapper.Map <Item>(model);

            item.scheduleId = scedule.CreateExpirationSchedule(item);
            UOW.Items.Add(item);
            UOW.Compelete();
            RS.data = model;
            return(RS);
        }
        public IResponse GetBackToDefaultTime(int BranchId)
        {
            var ServerDateTime     = DateTime.Now.AddServerTimeHours();
            var SelectedBranchTime = UOW.BranchConfigurations.SingleOrDefault(bc => bc.BranchId == BranchId && bc.CreatedAt.Date == ServerDateTime.Date);

            if (SelectedBranchTime != null)
            {
                UOW.BranchConfigurations.Remove(SelectedBranchTime);
            }
            UOW.Compelete();
            return(response);
        }
Exemple #5
0
        public IResponse AdminApproveTask(List <int> taskIds)
        {
            foreach (var taskId in taskIds)
            {
                var selectedTask = UOW.Tasks.SingleOrDefault(t => t.Id == taskId && t.ApprovedByMe == true);
                if (selectedTask != null)
                {
                    selectedTask.TaskStateId = 3;
                }
            }

            UOW.Compelete();
            return(response);
        }
        public IResponse Create(DepartementCreateModel model)
        {
            Departement newDepartement = mapper.Map <Departement>(model);

            UOW.Departements.Add(newDepartement);
            UOW.Compelete();
            return(response);
        }
        public IRequestResult Create(CreateItemType model)
        {
            ItemType itemType = mapper.Map <ItemType>(model);

            UOW.ItemTypes.Add(itemType);
            UOW.Compelete();
            RS.data = model;
            return(RS);
        }
Exemple #8
0
        public IResponse Create(BranchCreateModel model)
        {
            Branch newBranch = mapper.Map <Branch>(model);

            UOW.Branches.Add(newBranch);
            UOW.Compelete();
            foreach (int id in model.DeptIds)
            {
                var selectedDept = UOW.Departements.SingleOrDefault(d => d.Id == id);
                if (selectedDept != null)
                {
                    var newBranchDepartement = new BranchDepartement()
                    {
                        BranchId = newBranch.Id, DepartementId = id
                    };
                    UOW.BranchDepartement.Add(newBranchDepartement);
                }
            }
            UOW.Compelete();
            return(response);
        }
Exemple #9
0
 public IResponse Create(EventCreateModel model, int LoggedUser)
 {
     UOW.Events.Add(new ResourceEvent
     {
         CreatedById = LoggedUser,
         Start       = model.Start,
         End         = model.End,
         Name        = model.Name,
         Location    = model.Location,
     });
     UOW.Compelete();
     return(response);
 }
Exemple #10
0
        public async Task <IResponse> CreateManagerOrEmployee(AddManagerOrEmployee clerk)
        {
            AppUser newAppUser = new AppUser
            {
                UserName       = clerk.UserName,
                Email          = clerk.Email,
                EmailConfirmed = true,
            };
            var result = await userManager.CreateAsync(newAppUser, clerk.Password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(newAppUser, clerk.RoleName);

                if (clerk.RoleName == "MANAGER")
                {
                    UOW.Managers.Add(new AppUserManager()
                    {
                        UserId = newAppUser.Id, BranchId = clerk.BranchId
                    });
                }
                else
                {
                    var selectedBranchDepartement = UOW.BranchDepartement.SingleOrDefault(bd => bd.BranchId == clerk.BranchId && bd.DepartementId == clerk.DepartementId);
                    if (selectedBranchDepartement != null)
                    {
                        UOW.Employees.Add(new AppUserEmployee()
                        {
                            UserId = newAppUser.Id, BranchDepartementId = selectedBranchDepartement.Id
                        });
                    }
                }
                UOW.Compelete();
            }
            else
            {
                response.error_EN = result.Errors.Select(e => e.Description).FirstOrDefault();
                response.status   = false;
            }
            return(response);
        }