Esempio n. 1
0
        /// <inheritdoc />
        public void Add(MspProject project)
        {
            AddProjectCode(project);

            foreach (var request in project.Requests)
            {
                AddRequest(request, project.Code);
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public IEnumerable <MspProject> GetAll()
        {
            var projects = new List <MspProject>();

            var result = Connection.Query(
                "SELECT wf.workorderid, wf.udf_char1, wo.title, wo.description, wo.siteid, cs.technicianid, cs.ts_starttime, cs.ts_endtime, cs.worklogtypeid, wlf.udf_long1 " +
                "FROM workorder_fields as wf " +
                "LEFT JOIN workorder as wo ON wf.workorderid = wo.workorderid " +
                "LEFT JOIN workordertocharge as wotc ON wf.workorderid = wotc.workorderid " +
                "LEFT JOIN chargestable as cs ON wotc.chargeid = cs.chargeid " +
                "LEFT JOIN worklog_fields as wlf ON cs.chargeid = wlf.worklogid " +
                "ORDER BY udf_char1", transaction: Transaction);

            MspProject project        = null;
            MspRequest currentRequest = null;

            foreach (var res in result)
            {
                // Requests that don't belong to a project are skipped
                if (string.IsNullOrEmpty(res.udf_char1))
                {
                    continue;
                }

                // Create a new project when a new project code is encountered
                if (project == null || !string.Equals(res.udf_char1, project.Code))
                {
                    project = new MspProject(0, res.udf_char1)
                    {
                        Code     = res.udf_char1,
                        Requests = new List <MspRequest>()
                    };
                    projects.Add(project);
                }

                // Create a new request when a new request title is encountered
                if (currentRequest == null || !string.Equals(res.title, currentRequest.Title))
                {
                    currentRequest = new MspRequest(res.title, res.description, res.siteid);
                    project.AddRequest(currentRequest);
                }

                var worklog = new MspWorklog(
                    new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(res.ts_starttime),
                    new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(res.ts_endtime),
                    res.description,
                    res.udf_long1,
                    res.technicianid
                    );

                currentRequest.AddWorklog(worklog);
            }

            return(projects);
        }
Esempio n. 3
0
        private void AddProjectCode(MspProject project)
        {
            // Creates the project code in MSP
            const string query = "INSERT INTO udf_picklistvalues(picklistid, tablename, columname, value) " +
                                 "VALUES (nextval('picklist_id_seq'), WorkOrder_Fields, UDF_CHAR1, @ProjectName)";

            var param = new
            {
                ProjectName = project.Code
            };

            Connection.Execute(query, param, Transaction);
        }
Esempio n. 4
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="mspProject">The MSP project</param>
 /// <param name="dapperUnitOfWorkFactory"><see cref="IDapperUnitOfWorkFactory"/></param>
 public MspProjectAdapter(MspProject mspProject, IDapperUnitOfWorkFactory dapperUnitOfWorkFactory)
 {
     _mspProject = mspProject;
     _dapperUnitOfWorkFactory = dapperUnitOfWorkFactory;
     AccountCode = GetAccountCode();
 }
Esempio n. 5
0
 public void Remove(MspProject project)
 {
     throw new NotImplementedException();
 }
        // Sets the accounts on all requests
        private static bool HasSameAccount(MspProject project)
        {
            var siteId = project.Requests.First().SiteId;

            return(project.Requests.All(x => x.SiteId == siteId));
        }