Beispiel #1
0
        public GeneralResponse EditToDoResult(EditToDoResultRequest request, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ToDoResult toDoResult = new ToDoResult();
                toDoResult = _toDoResultRepository.FindBy(request.ID);
                toDoResult.ModifiedDate          = PersianDateTime.Now;
                toDoResult.ModifiedEmployee      = _employeeRepository.FindBy(ModifiedEmployeeID);
                toDoResult.SecondaryClosed       = request.SecondaryClosed;
                toDoResult.Remindable            = request.Remindable;
                toDoResult.ToDoResultDescription = request.ToDoResultDescription;
                toDoResult.RemindeTime           = request.RemindeTime;

                _toDoResultRepository.Save(toDoResult);
                _uow.Commit();
            }

            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }
Beispiel #2
0
        public GeneralResponse DeleteToDoResultAttachment(Guid ToDoID, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            ToDoResult toDoResult = _toDoResultRepository.FindBy(ToDoID);
            string     path       = toDoResult.Attachment;

            try
            {
                toDoResult.Attachment       = null;
                toDoResult.AttachmentType   = null;
                toDoResult.ModifiedDate     = PersianDateTime.Now;
                toDoResult.ModifiedEmployee = _employeeRepository.FindBy(ModifiedEmployeeID);

                _toDoResultRepository.Save(toDoResult);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            if (response.hasError != true)
            {
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                    if (ex.InnerException != null)
                    {
                        response.ErrorMessages.Add(ex.InnerException.Message);
                    }
                }
            }

            return(response);
        }
Beispiel #3
0
        public GeneralResponse SecondaryClose(Guid ToDoResultID, string ToDoResultDescription, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ToDoResult toDoResul = _toDoResultRepository.FindBy(ToDoResultID);
                toDoResul.ModifiedDate          = PersianDateTime.Now;
                toDoResul.ModifiedEmployee      = _employeeRepository.FindBy(ModifiedEmployeeID);
                toDoResul.ToDoResultDescription = ToDoResultDescription;
                toDoResul.SecondaryClosed       = true;
                _toDoResultRepository.Save(toDoResul);


                // د صورتی که ایجاد کننده با ارجاع دهنده برابر بود و وظیفه فقط برای ایجاد کننده درج شده باشد بستن اصلی نیز انجام شود

                Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
                Criterion criteriaToDoID            = new Criterion("ToDo.ID", toDoResul.ToDo.ID, CriteriaOperator.Equal);
                query.Add(criteriaToDoID);
                Response <ToDoResult> toDoResults = _toDoResultRepository.FindBy(query, -1, -1);
                if (toDoResults.data.Count() == 1)
                {
                    ToDo toDo = _toDoRepository.FindBy(toDoResul.ToDo.ID);
                    toDo.PrimaryClosed    = true;
                    toDo.ModifiedEmployee = _employeeRepository.FindBy(ModifiedEmployeeID);
                    toDo.ModifiedDate     = PersianDateTime.Now;
                    _toDoRepository.Save(toDo);
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Beispiel #4
0
        public GeneralResponse AddToDoResultAttachment(AddToDoResultAttachmentRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ToDoResult toDoResult = _toDoResultRepository.FindBy(request.ToDoResultID);

                #region Rename The file

                // extract the extention
                var fileExtention = Path.GetExtension(request.Attachment);
                // Get directory
                var directory = Path.GetDirectoryName(request.Attachment);
                // create filename
                string fileName = directory + "\\ToDoResult_" + request.ToDoResultID + fileExtention;
                // Rename file
                //File.Move(request.Attachment, fileName);

                #endregion

                toDoResult.AttachmentType   = fileExtention;
                toDoResult.Attachment       = fileName;
                toDoResult.ModifiedDate     = PersianDateTime.Now;
                toDoResult.ModifiedEmployee = _employeeRepository.FindBy(CreateEmployeeID);

                _toDoResultRepository.Save(toDoResult);
                _uow.Commit();
            }

            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Beispiel #5
0
        public GetGeneralResponse <IEnumerable <ToDoResultView> > GetToDoResults(IEnumerable <Guid> ToDoResultsID)
        {
            GetGeneralResponse <IEnumerable <ToDoResultView> > response = new GetGeneralResponse <IEnumerable <ToDoResultView> >();

            try
            {
                IList <ToDoResult> _todoResults = new List <ToDoResult>();

                foreach (Guid Id in ToDoResultsID)
                {
                    Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();

                    Criterion criteriaEmployeeID = new Criterion("ID", ToDoResultsID, CriteriaOperator.Equal);
                    query.Add(criteriaEmployeeID);

                    ToDoResult toDoResults = _toDoResultRepository.FindBy(Id);
                    _todoResults.Add(toDoResults);

                    foreach (var todoResult in _todoResults)
                    {
                        if (todoResult.Attachment != null)
                        {
                            todoResult.Attachment =
                                todoResult.Attachment.Replace(@"\", "/")
                                .Substring(todoResult.Attachment.IndexOf("data"));
                        }
                    }
                    response.data       = _todoResults.ConvertToToDoResultViews();
                    response.totalCount = _todoResults.Count();
                }
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException.Message != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }
Beispiel #6
0
        public GeneralResponse AddTodo(AddToDoRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                ToDo toDo = new ToDo();
                toDo.ID             = Guid.NewGuid();
                toDo.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                toDo.CreateDate     = PersianDateTime.Now;
                toDo.Customer       = _customerRepository.FindBy(request.CustomerID);
                if (request.EndDate != null)
                {
                    toDo.EndDate = request.EndDate;
                }
                else
                {
                    toDo.EndDate = request.StartDate;
                }
                toDo.EndTime         = request.EndTime;
                toDo.StartDate       = request.StartDate;
                toDo.StartTime       = request.StartTime;
                toDo.PrimaryClosed   = false;
                toDo.PriorityType    = PriorityType.High;
                toDo.ToDoTitle       = request.ToDoTitle;
                toDo.ToDoDescription = request.ToDoDescription;
                toDo.RowVersion      = 1;
                // اگر لیست کارمندان آمد یعنی وظیفه مربوط به کارمندان است
                if (request.EmployeeIDs != null)
                {
                    IList <ToDoResult> toDoResults = new List <ToDoResult>();
                    foreach (Guid iD in request.EmployeeIDs)
                    {
                        Employee employee = _employeeRepository.FindBy(iD);

                        ToDoResult toDoResult = new ToDoResult();
                        toDoResult.ID                    = Guid.NewGuid();
                        toDoResult.CreateEmployee        = _employeeRepository.FindBy(CreateEmployeeID);
                        toDoResult.CreateDate            = PersianDateTime.Now;
                        toDoResult.ToDo                  = toDo;
                        toDoResult.Remindable            = request.Remindable;
                        toDoResult.RemindeTime           = request.RemindeTime;
                        toDoResult.ReferedEmployee       = employee;
                        toDoResult.RowVersion            = 1;
                        toDoResult.ToDoResultDescription = "";
                        toDoResults.Add(toDoResult);
                    }
                    toDo.ToDoResults = toDoResults;
                    toDo.IsGrouped   = false;
                }
                //اگر لیست گروه ها آمد به معنی اینکه این وظیفه گروهی است
                if (request.GroupIDs != null)
                {
                    IList <ToDoResult> toDoResults = new List <ToDoResult>();
                    foreach (Guid iD in request.GroupIDs)
                    {
                        IEnumerable <Employee> employees = _employeeRepository.FindAll().Where(x => x.Group.ID == iD);
                        foreach (Employee employee in employees)
                        {
                            ToDoResult toDoResult = new ToDoResult();
                            toDoResult.ID                    = Guid.NewGuid();
                            toDoResult.CreateEmployee        = _employeeRepository.FindBy(CreateEmployeeID);
                            toDoResult.CreateDate            = PersianDateTime.Now;
                            toDoResult.ToDo                  = toDo;
                            toDoResult.Remindable            = request.Remindable;
                            toDoResult.RemindeTime           = request.RemindeTime;
                            toDoResult.ReferedEmployee       = employee;
                            toDoResult.RowVersion            = 1;
                            toDoResult.ToDoResultDescription = "";
                            toDoResults.Add(toDoResult);
                        }
                    }
                    toDo.ToDoResults = toDoResults;
                    toDo.IsGrouped   = false;
                }
                if (request.GroupIDs == null && request.EmployeeIDs == null)
                {
                    IList <ToDoResult> toDoResults = new List <ToDoResult>();

                    ToDoResult toDoResult = new ToDoResult();
                    toDoResult.ID                    = Guid.NewGuid();
                    toDoResult.CreateEmployee        = _employeeRepository.FindBy(CreateEmployeeID);
                    toDoResult.CreateDate            = PersianDateTime.Now;
                    toDoResult.ToDo                  = toDo;
                    toDoResult.Remindable            = request.Remindable;
                    toDoResult.RemindeTime           = request.RemindeTime;
                    toDoResult.ReferedEmployee       = _employeeRepository.FindBy(CreateEmployeeID);
                    toDoResult.RowVersion            = 1;
                    toDoResult.ToDoResultDescription = "";
                    toDoResults.Add(toDoResult);
                    toDo.ToDoResults = toDoResults;
                    toDo.IsGrouped   = false;
                }
                _toDoRepository.Add(toDo);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }
Beispiel #7
0
 public static ToDoResultView ConvertToToDoResultView(this ToDoResult toDoResult)
 {
     return(Mapper.Map <ToDoResult, ToDoResultView>(toDoResult));
 }