public async Task <ActionResult <WorkHour> > PostWorkHour(WorkHour workHour)
        {
            _context.WorkHours.Add(workHour);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetWorkHour", new { id = workHour.WorkHourId }, workHour));
        }
示例#2
0
        public async Task <IActionResult> PutWorkHour(Guid id, WorkHour workHour)
        {
            if (id != workHour.WorkHourId)
            {
                return(BadRequest());
            }

            _context.Entry(workHour).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkHourExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task <ActionResult <dynamic> > GetById(int id)
        {
            int userId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value);
            int roleId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value);

            if (roleId == (int)EnumRole.Administrator)
            {
                userId = 0;
            }

            if (id <= 0)
            {
                return(BadRequest(new { success = false, data = new { }, messages = "Send Id workHour it's required" }));
            }

            try
            {
                WorkHour data_workHour = workHourRepository.GetById(id);
                if (data_workHour == null)
                {
                    return(Ok(new { success = false, data = new { }, messages = "No having workHour with the Id" }));
                }
                return(Ok(new { success = true, data = data_workHour, messages = "Item successfull finded" }));
            }
            catch (Exception ex)
            {
                return(CatchError(ex, "Find workHour by Id"));
            }
        }
        private void BTNRemove_Click_1(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("سوف يتم مسح هذا العنصر؟", "تأكيد الحذف ", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                try
                {
                    WorkHour workHour = DGWorkHours.SelectedItem as WorkHour;
                    WorkHour row      = (from p in context.WorkHours
                                         where p.Id == workHour.Id
                                         select p).Single();
                    context.WorkHours.Remove(row);
                    context.SaveChanges();
                    loadData();
                }
                catch (Exception) {
                    MessageBox.Show("حدث خطب ما برجاء المحاولة مرة أخري" +
                                    "تـأكد من ارتباط البيانات بمعومات اخري");
                }
            }
            else
            {
                MessageBox.Show("لاتقلق لم تمسح اي بيانات");
            }
        }
        public List <string> SaveWorkHours(WorkHourJson workHourJson)
        {
            List <string> result = new List <string>();

            try
            {
                UnitOfWork       uow         = new UnitOfWork();
                UserManager      userManager = new UserManager(uow);
                TaskManager      taskManager = new TaskManager(uow);
                ProjectManager   prjManager  = new ProjectManager(uow);
                TimeSheetManager tsManager   = new TimeSheetManager(uow);
                Validations      validate    = new Validations();
                User             currUser    = new UserHelper().GetCurrent();
                WorkHour         workHour    = workHourJson.ToWorkHour();
                workHour.Task            = taskManager.GetByID(workHour.TaskID);
                workHour.TaskID          = workHour.Task.ID;
                workHour.Project         = prjManager.GetByID(workHourJson.ProjectID);
                workHour.ProjectId       = workHour.Project.ID;
                workHour.EmployeeID      = currUser.ID;
                workHour.Employee        = userManager.GetByID(currUser.ID);
                workHour.WorkflowStage   = new WorkflowManager(uow).FirstStage();
                workHour.WorkflowStageID = workHour.WorkflowStage.ID;
                workHour.Description     = workHourJson.Description;
                tsManager.SaveWorkHour(workHour);
                HistoryUtilities.RegisterSaveHistory(workHour);
            }

            catch (ValidationException ex)
            {
                result = ex.Errors;
            }
            return(result);
        }
        public void SetNewStage(WorkHour workHour)
        {
            var entity = _RASContext.WorkHours.Find(workHour.ID);

            entity.WorkflowStage   = workHour.WorkflowStage;
            entity.WorkflowStageID = workHour.WorkflowStageID;
        }
示例#7
0
        public async Task <ActionResult <dynamic> > DeleteWorkHour(int id)
        {
            int userId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value);
            int roleId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value);

            if (roleId == (int)EnumRole.Administrator)
            {
                userId = 0;
            }

            if (id <= 0)
            {
                return(BadRequest(new { success = false, data = new { }, messages = "Send Id workHour" }));
            }

            try
            {
                WorkHour data_workHour = workHourRepository.GetById(id);
                if (data_workHour == null)
                {
                    return(Ok(new { success = false, data = new { }, messages = "No having workHour with the Id" }));
                }
                workHourRepository.Delete(data_workHour);
                return(Ok(new { success = true, data = id, messages = "Item successfull deleted" }));
            }
            catch (Exception ex)
            {
                return(CatchError(ex, string.Format("Delete workHour id ({0})", id)));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            WorkHour workHour = db.WorkHours.Find(id);

            db.WorkHours.Remove(workHour);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// اضافه کردن ساعت کاری جدید به پایگاه داده
        /// </summary>
        /// <param name="workHour">موجودیت مرتبط با ساعت کاری جدید</param>
        public void Add(WorkHour workHour)
        {
            var entity = new WorkHour();

            entity.ID = Guid.NewGuid();
            FillEntity(workHour, entity);
            _RASContext.WorkHours.Add(entity);
        }
示例#10
0
        public async Task <ActionResult <dynamic> > UpdateWorkHour([FromBody] WorkHour workHour)
        {
            List <string> validations_erro = new List <string>();

            if (workHour.Id <= 0)
            {
                validations_erro.Add("WorkHour id is required");
            }

            if (workHour.CreatedAt == null)
            {
                validations_erro.Add("WorkHour created date is required");
            }

            if (workHour.ProjectId <= 0)
            {
                validations_erro.Add("WorkHour project id is required");
            }

            if (workHour.UserId <= 0)
            {
                validations_erro.Add("WorkHour user id is required");
            }

            var projectUser = projectUserRepository.ListByUser(workHour.UserId, workHour.ProjectId);

            if (projectUser.Count() == 0)
            {
                validations_erro.Add("User don't has vinculate to project");
            }

            if (validations_erro.Count() > 0)
            {
                return(BadRequest(new { success = false, data = new { }, messages = validations_erro }));
            }

            try
            {
                if (workHour.FinishedAt != null)
                {
                    var     d1           = DateTime.Parse(workHour.CreatedAt.ToString());
                    var     d2           = DateTime.Parse(workHour.FinishedAt.ToString());
                    var     totalMinutes = float.Parse((d2 - d1).Minutes.ToString());
                    var     totalHours   = float.Parse(((d2 - d1).Hours * 60).ToString());
                    decimal totalTime    = Decimal.Parse(((totalHours + totalMinutes) / 60).ToString());
                    workHour.TotalTime = totalTime;
                }

                WorkHour data_workHour = workHourRepository.Save(workHour);
                return(Ok(new { success = true, data = data_workHour, messages = "Item successfull updated" }));
            }
            catch (Exception ex)
            {
                return(CatchError(ex, string.Format("Update workHour id({0})", workHour.Id)));
            }
        }
示例#11
0
 public ActionResult Edit([Bind(Include = "ID,WorkHour1")] WorkHour workHour)
 {
     if (ModelState.IsValid)
     {
         db.Entry(workHour).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(workHour));
 }
        public static WorkHourJson ToJson(this WorkHour entity)
        {
            var result = new WorkHourJson();

            result.ID     = entity.ID;
            result.Date   = entity.Date;
            result.TaskID = entity.Task.ID;
            result.Hours  = entity.Hours;

            return(result);
        }
 public ActionResult Edit([Bind(Include = "Id,PlaceId,Weekno,OpenHour,CloseHour")] WorkHour workHour)
 {
     if (ModelState.IsValid)
     {
         db.Entry(workHour).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PlaceId = new SelectList(db.Places, "Id", "Name", workHour.PlaceId);
     return(View(workHour));
 }
        public ActionResult Create([Bind(Include = "Id,PlaceId,Weekno,OpenHour,CloseHour")] WorkHour workHour)
        {
            if (ModelState.IsValid)
            {
                db.WorkHours.Add(workHour);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PlaceId = new SelectList(db.Places, "Id", "Name", workHour.PlaceId);
            return(View(workHour));
        }
示例#15
0
 public void Delete(WorkHour item)
 {
     if (item.Id > 0)
     {
         using (var transaction = databaseContext.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
         {
             databaseContext.Entry(item).State = EntityState.Deleted;
             databaseContext.SaveChanges();
             transaction.Commit();
         }
     }
 }
 private static void FillEntity(WorkHour workHour, WorkHour entity)
 {
     entity.Date            = workHour.Date;
     entity.ProjectId       = workHour.ProjectId;
     entity.EmployeeID      = workHour.EmployeeID;
     entity.TaskID          = workHour.TaskID;
     entity.Hours           = workHour.Hours;
     entity.PreviousStage   = workHour.PreviousStage;
     entity.WorkflowStageID = workHour.WorkflowStageID;
     entity.ID          = workHour.ID;
     entity.Action      = workHour.Action;
     entity.Description = workHour.Description;
 }
示例#17
0
    public void Main()
    {
        var o = new WorkHour()
        {
            created   = DateTime.Now,
            dayId     = 0,
            deleted   = false,
            endTime   = new TimeSpan(0, 0, 2),
            startTime = new TimeSpan(0, 0, 2),
            id        = 0,
        };

        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(o));
    }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         WorkHour deleteWorkHour = _workHourBll.GetBLL(selectedID);
         selectedID = 0;
         _workHourBll.DeleteBLL(deleteWorkHour);
         RefleshGrid();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#19
0
        // GET: admin/WorkHours/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkHour workHour = db.WorkHours.Find(id);

            if (workHour == null)
            {
                return(HttpNotFound());
            }
            return(View(workHour));
        }
示例#20
0
        public static void RegisterSendHistory(WorkHour workHour, IUnitOfWork uow, User currentUser)
        {
            var history = new WorkHourHistory();

            var historyManager = new WorkHourHistoryManager(uow);

            history.Action      = "Send";
            history.Date        = DateTime.Now;
            history.Description = "ارسال کارکرد به مدیر";
            history.ManagerID   = currentUser.ID;
            history.EntityId    = workHour.ID;
            history.StageID     = workHour.WorkflowStageID;
            historyManager.Add(history);
        }
示例#21
0
        public static void RegisterSaveHistory(WorkHour workHour)
        {
            UnitOfWork uow            = new UnitOfWork();
            var        history        = new WorkHourHistory();
            var        userManager    = new UserManager(uow);
            var        historyManager = new WorkHourHistoryManager(uow);

            history.Action      = "Register";
            history.Date        = DateTime.Now;
            history.Description = "ثبت کارکرد جدید";
            history.ManagerID   = new UserHelper().GetCurrent().ID;
            history.WorkHourID  = workHour.ID;
            history.StageID     = workHour.WorkflowStageID;
            historyManager.Add(history);
        }
        // GET: admin/WorkHours/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkHour workHour = db.WorkHours.Find(id);

            if (workHour == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PlaceId = new SelectList(db.Places, "Id", "Name", workHour.PlaceId);
            return(View(workHour));
        }
示例#23
0
        public static void RegisterSendHistory(WorkHour workHour)
        {
            UnitOfWork uow     = new UnitOfWork();
            var        history = new WorkHourHistory();

            var historyManager = new WorkHourHistoryManager(uow);

            history.Action      = "Send";
            history.Date        = DateTime.Now;
            history.Description = "ارسال کارکرد به مدیر";
            history.ManagerID   = new UserHelper().GetCurrent().ID;
            history.WorkHourID  = workHour.ID;
            history.StageID     = workHour.WorkflowStageID;
            historyManager.Add(history);
        }
示例#24
0
        public static void RegisterSaveHistory(WorkHour workHour, IUnitOfWork uow, User currentUser)
        {
            var history        = new WorkHourHistory();
            var userManager    = new UserManager(uow);
            var historyManager = new WorkHourHistoryManager(uow);

            history.Action          = "Register";
            history.Date            = DateTime.Now;
            history.Description     = "ثبت کارکرد جدید";
            history.UserDescription = workHour.Description;
            history.ManagerID       = currentUser.ID;
            history.EntityId        = workHour.ID;
            history.StageID         = workHour.WorkflowStageID;
            historyManager.Add(history);
        }
示例#25
0
        public WorkHourJson ToJson(WorkHour entity)
        {
            var result = new WorkHourJson();

            result.ID                 = entity.ID;
            result.Action             = entity.Action;
            result.PersianDate        = DateUtility.GetPersianDate(entity.Date);
            result.Description        = entity.Description;
            result.UserName           = entity.Employee.UserName;
            result.Hours              = entity.Hours;
            result.ProjectTitle       = entity.Project.Title;
            result.TaskTitle          = entity.Task.Title;
            result.WorkFlowStageTitle = entity.WorkflowStage.Title;
            return(result);
        }
示例#26
0
        public List <DevTop5WeekDto> DevTop5Week()
        {
            List <WorkHour>       userList   = new List <WorkHour>();
            List <DevTop5WeekDto> dataReturn = new List <DevTop5WeekDto>();

            var dateWeek = DateTime.Now.AddDays(-7);
            var today    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

            var listWorks = databaseContext.WorkHour.Where(wh => wh.FinishedAt != null && wh.CreatedAt >= dateWeek && wh.FinishedAt <= today).ToList();

            foreach (var lw in listWorks)
            {
                var lwUser = userList.Where(x => x.UserId == lw.UserId).FirstOrDefault();
                if (lwUser == null)
                {
                    lwUser = new WorkHour
                    {
                        UserId    = lw.UserId,
                        TotalTime = 0
                    };

                    lwUser.TotalTime += lw.TotalTime;
                    userList.Add(lwUser);
                }
                else
                {
                    lwUser.TotalTime += lw.TotalTime;
                }
            }

            userList = userList.OrderByDescending(x => x.TotalTime).Take(5).ToList();
            List <int> ids = userList.Select(s => s.UserId).ToList();

            var users = databaseContext.User.Where(x => ids.Contains(x.Id)).ToList();

            foreach (var u in users)
            {
                DevTop5WeekDto dt5 = new DevTop5WeekDto
                {
                    Id         = u.Id,
                    Name       = u.Name,
                    TotalHours = userList.Where(x => x.UserId == u.Id).FirstOrDefault().TotalTime
                };
                dataReturn.Add(dt5);
            }

            return(dataReturn);
        }
        public static WorkHour ToWorkHour(this WorkHourJson jsonObject)
        {
            WorkHour result = new WorkHour();

            result.ID              = Guid.NewGuid();
            result.Date            = jsonObject.Date;
            result.EmployeeID      = jsonObject.EmployeeID;
            result.TaskID          = jsonObject.TaskID;
            result.ProjectId       = jsonObject.ProjectID;
            result.Hours           = Math.Round(TimeSpan.Parse(jsonObject.Hours.ToString()).TotalHours, 2);
            result.WorkflowStageID = jsonObject.WorkflowStageID;



            return(result);
        }
示例#28
0
 public WorkHour Save(WorkHour item)
 {
     using (var transaction = databaseContext.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
     {
         if (item.Id == 0)
         {
             databaseContext.WorkHour.Add(item);
         }
         else
         {
             databaseContext.Entry(item).State = EntityState.Modified;
         }
         databaseContext.SaveChanges();
         transaction.Commit();
     }
     return(item);
 }
示例#29
0
        public IActionResult RecordHours(WorkHour workHour)
        {
            workHour.Date = DateTime.Now;
            IEnumerable <WorkHour> empWorkedHours = context.WorkHours.Where(h => h.EmployeeId == workHour.EmployeeId).Where(h => h.Date.Date == DateTime.Now.Date);

            if (empWorkedHours.Count() > 0)
            {
                TempData["errorMessage"] = "You have already recorded hours for today.";
                return(RedirectToAction("ClockIn"));
            }
            else
            {
                context.WorkHours.Add(workHour);
                context.SaveChanges();
                TempData["successMessage"] = "Hours have been updated succefully.";
                return(RedirectToAction("ClockIn"));
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                WorkHour newWorkHour = new WorkHour();

                newWorkHour.Name       = txtWorkHourName.Text;
                newWorkHour.StartHour  = mtxtStartHour.Text;
                newWorkHour.EndHour    = mtxtEndHour.Text;
                newWorkHour.EmployeeId = (int)cmbEmployeeID.SelectedValue;

                _workHourBll.SaveBLL(newWorkHour);
                RefleshGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }