コード例 #1
0
ファイル: ProjectsService.cs プロジェクト: evgeniynet/APIBeta
        public object Get(Projects_List request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            return(Models.Projects.GetProjects(hdUser.OrganizationId, hdUser.DepartmentId, 0, hdUser.IsTechAdmin ? 0 : hdUser.UserId, instanceConfig.AccountManager, request.page, request.limit));
        }
コード例 #2
0
        public object Get(FB_Staff request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            return(FBStaffs.GetFBStaff(instanceConfig, request.page, request.limit));
        }
コード例 #3
0
        public object Get(FB_Tasks request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            int projectID = 0;

            if (!int.TryParse(request.project, out projectID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect project id");
            }

            return(FBTasks.GetFBTasks(instanceConfig, request.page, request.limit, projectID));
        }
コード例 #4
0
        public object Post(FB_Time request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);
            bool            isProjectLog   = false;
            string          notes          = "";
            int             staffID        = 0;
            DateTime        date           = DateTime.MinValue;

            if (request.is_project_log.HasValue)
            {
                isProjectLog = request.is_project_log.Value;
            }
            if (request.notes != null)
            {
                notes = request.notes;
            }
            if (request.fb_staff_id.HasValue)
            {
                staffID = request.fb_staff_id.Value;
            }
            if (request.date.HasValue)
            {
                date = request.date.Value;
            }
            try
            {
                string result = FBTimeEntries.CreateTimeEntry(hdUser, instanceConfig, staffID, request.fb_project_id, request.fb_task_type_id,
                                                              request.hours, notes, date, request.time_id, isProjectLog);
                if (result == "ok")
                {
                    return(new HttpResult("", HttpStatusCode.OK));
                }
                else
                {
                    throw new HttpError(result.Replace("\n", " ").Replace("\r", " "));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(ex.Message.Replace("\n", " ").Replace("\r", " "));
            }
        }
コード例 #5
0
        public object Get(FB_Projects request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            int clientID = 0;

            if (!int.TryParse(request.client, out clientID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect client id");
            }
            int staffID = 0;

            if (!int.TryParse(request.staff, out staffID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect staff id");
            }

            return(FBProjects.GetFBProjects(instanceConfig, request.page, request.limit, clientID, staffID));
        }
コード例 #6
0
        static object ChangeLocation(ApiUser hdUser, int id, string name, string description, int?parent_location_id, int?type_id, bool?is_active, int?auditor_id, int?audit_days, Models.Location old_loc = null)
        {
            Guid organizationId = hdUser.OrganizationId;
            int  departmentId   = hdUser.DepartmentId;
            int  m_ID           = id;
            bool _isNew         = m_ID == 0 ? true : false;

            bool?Status = null;

            int accountId = hdUser.AccountId;

            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            if (!_isNew)
            {
                auditor_id         = !auditor_id.HasValue ? old_loc.AuditorId : auditor_id;
                auditor_id         = !audit_days.HasValue ? old_loc.AuditDays : audit_days;
                accountId          = accountId == 0 ? old_loc.AccountId : accountId;
                Status             = is_active.HasValue ? is_active : old_loc.IsActive;
                parent_location_id = parent_location_id.HasValue ? parent_location_id : old_loc.ParentId;
                type_id            = type_id.HasValue ? type_id : old_loc.TypeId;
            }
            else
            {
                accountId          = accountId == 0 ? -1 : accountId;
                Status             = is_active ?? true;
                parent_location_id = parent_location_id ?? 0;
                type_id            = type_id ?? 0;
            }

            /*if (!instanceConfig.EnableAssetAuditor || !instanceConfig.AssetTracking)
             * {
             * throw new HttpError("Assets is not enabled for this instance.");
             * }*/

            if (bigWebApps.bigWebDesk.Data.Locations.IsNameExists(organizationId, departmentId, accountId, parent_location_id.Value, type_id, name, m_ID))
            {
                throw new ServiceStack.Common.Web.HttpError("The " + instanceConfig.Names.location.s + " name \"" + name + "\" is already exists. Please, enter another name.");
            }


            bool LocationAuditEnabled = auditor_id.HasValue && auditor_id.Value > 0;
            int? AuditorId            = auditor_id;
            int? AditPeriodDays       = audit_days;

            if (LocationAuditEnabled)// && instanceConfig.)
            {
                AuditorId      = auditor_id;
                AditPeriodDays = audit_days;
            }


            try
            {
                m_ID = bigWebApps.bigWebDesk.Data.Locations.Update(organizationId, departmentId, m_ID, parent_location_id.Value, accountId, type_id, name, Status,
                                                                   description, false, LocationAuditEnabled, AuditorId, AditPeriodDays);
            }
            catch
            {
                throw new ServiceStack.Common.Web.HttpError("The " + instanceConfig.Names.location.s + " name \"" + name + "\" is already exists. Please, enter another name.");
            }

            /*if (_isNew)
             * {
             *  DataTable dt = bigWebApps.bigWebDesk.Data.Locations.LocationAliases.SelectAll(organizationId, departmentId, m_ID);
             *  foreach (DataRow _row in dt.Rows) bigWebApps.bigWebDesk.Data.Locations.LocationAliases.Update(organizationId, departmentId, 0, m_ID, _row["LocationAliasName"].ToString());
             * }
             */
            return(m_ID);
        }
コード例 #7
0
 public object Post(FB_Time request)
 {
     ApiUser hdUser = request.ApiUser;
     Instance_Config instanceConfig = new Models.Instance_Config(hdUser);
     bool isProjectLog = false;
     string notes = "";
     int staffID = 0;
     DateTime date = DateTime.MinValue;
     if (request.is_project_log.HasValue)
     {
         isProjectLog = request.is_project_log.Value;
     }
     if (request.notes != null)
     {
         notes = request.notes;
     }
     if (request.fb_staff_id.HasValue)
     {
         staffID = request.fb_staff_id.Value;
     }
     if (request.date.HasValue)
     {
         date = request.date.Value;
     }
     try
     {
         string result = FBTimeEntries.CreateTimeEntry(hdUser, instanceConfig, staffID, request.fb_project_id, request.fb_task_type_id,
             request.hours, notes, date, request.time_id, isProjectLog);
         if (result == "ok")
         {
             return new HttpResult("", HttpStatusCode.OK);
         }
         else
         {
             throw new HttpError(result.Replace("\n", " ").Replace("\r", " "));
         }
     }
     catch (Exception ex)
     {
         throw new HttpError(ex.Message.Replace("\n", " ").Replace("\r", " "));
     }
 }
コード例 #8
0
        public object Get(FB_Tasks request)
        {
            ApiUser hdUser = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            int projectID = 0;
            if (!int.TryParse(request.project, out projectID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect project id");
            }

            return FBTasks.GetFBTasks(instanceConfig, request.page, request.limit, projectID);
        }
コード例 #9
0
        public object Get(FB_Projects request)
        {
            ApiUser hdUser = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            int clientID = 0;
            if (!int.TryParse(request.client, out clientID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect client id");
            }
            int staffID = 0;
            if (!int.TryParse(request.staff, out staffID))
            {
                throw new HttpError(HttpStatusCode.NotFound, "incorrect staff id");
            }

            return FBProjects.GetFBProjects(instanceConfig, request.page, request.limit, clientID, staffID);
        }
コード例 #10
0
        public object Get(FB_Staff request)
        {
            ApiUser hdUser = request.ApiUser;
            Instance_Config instanceConfig = new Models.Instance_Config(hdUser);

            return FBStaffs.GetFBStaff(instanceConfig, request.page, request.limit);
        }
コード例 #11
0
ファイル: ProjectsService.cs プロジェクト: evgeniynet/APIBeta
 public object Get(Projects_List request)
 {
     ApiUser hdUser = request.ApiUser;
     Instance_Config instanceConfig = new Models.Instance_Config(hdUser);
     return Models.Projects.GetProjects(hdUser.OrganizationId, hdUser.DepartmentId, 0, hdUser.IsTechAdmin ? 0 : hdUser.UserId, instanceConfig.AccountManager, request.page, request.limit);
 }
コード例 #12
0
        internal static object SendInvoice(ApiUser hdUser, string invoice_id, string recipients, bool isPDFOnly = false)
        {
            Guid   organizationId = hdUser.OrganizationId;
            int    departmentId   = hdUser.DepartmentId;
            int    userId         = hdUser.UserId;
            string Email          = hdUser.LoginEmail;
            string userName       = hdUser.FullName;
            string department     = hdUser.DepartmentName;

            Models.Invoice invoice    = GetInvoice(organizationId, departmentId, invoice_id, false);
            int            AccountId  = invoice.AccountId;
            List <int>     intUserIds = new List <int>();

            string[] emails = recipients.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
            recipients         = "";
            invoice.recipients = AccountUsers.GetAccountUsers(organizationId, departmentId, invoice.AccountId);
            foreach (string email in emails)
            {
                if (!Utils.IsValidEmail(email))
                {
                    continue;
                }

                bool        isAccountingContact = true;
                int         userID    = 0;
                string      new_email = "";
                AccountUser user      = invoice.recipients.Find(r => r.Email.ToLower() == email.ToLower());
                if (user != null)
                {
                    isAccountingContact = user.AccountingContact;
                    userID    = user.Id;
                    new_email = user.Email;
                }
                else
                {
                    userId              = bigWebApps.bigWebDesk.Data.Accounts.InsertUserIntoAccount(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, email, 0, false);
                    new_email           = email;
                    isAccountingContact = false;
                }
                if (!isAccountingContact)
                {
                    bigWebApps.bigWebDesk.Data.Accounts.UpdateAccountContact(hdUser.OrganizationId, hdUser.DepartmentId, AccountId, userID, true);
                }
                recipients += new_email + ";";
            }

            int    ProjectId = invoice.ProjectId;
            int    invoiceID = invoice.Id.Value;
            string subject   = invoice.Customer + " | Invoice #" + invoiceID;
            string from      = "\"" + userName + " - " + department + "\"<" + Email + ">";

            if (!string.IsNullOrWhiteSpace(recipients))
            {
                Instance_Config instanceConfig = new Models.Instance_Config(hdUser);
                string          currency       = string.IsNullOrWhiteSpace(instanceConfig.Currency) ? "$" : instanceConfig.Currency;
                try
                {
                    string filename     = "Invoice-" + invoiceID.ToString() + ".pdf";
                    string logoURL      = string.Empty;
                    string logoImageUrl = Files.GetOrganizationLargeLogoUrl(organizationId);
                    if (!String.IsNullOrEmpty(logoImageUrl))
                    {
                        logoURL = logoImageUrl;
                    }
                    logoImageUrl = Files.GetInstanceLargeLogoUrl(hdUser.InstanceId);
                    if (!String.IsNullOrEmpty(logoImageUrl))
                    {
                        logoURL = logoImageUrl;
                    }
                    byte[] pdfBytes = null;
                    string body     = "";
                    try
                    {
                        pdfBytes = bigWebApps.bigWebDesk.Data.Invoice.ExportPDF(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency,
                                                                                instanceConfig.Names.tech.a, instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber, logoURL);
                        if (isPDFOnly)
                        {
                            var sfile = new System.IO.MemoryStream(pdfBytes);
                            return(new BWA.bigWebDesk.Api.Services.FilesService.FileResult(sfile, "application/pdf", filename));
                        }
                        body = bigWebApps.bigWebDesk.Data.Invoice.ExportHtml(organizationId, hdUser.InstanceId, departmentId, userId, invoiceID, "https://app.sherpadesk.com", currency, instanceConfig.Names.tech.a,
                                                                             instanceConfig.Names.ticket.a, instanceConfig.ProjectTracking, instanceConfig.Names.user.a, instanceConfig.QBUseQBInvoiceNumber);
                    }
                    catch
                    {
                        throw new HttpError(HttpStatusCode.NotFound, "Cannot create invoice with provided data.");
                    }
                    MailNotification _mail_notification = new MailNotification(organizationId, departmentId, userId, from, recipients, subject, body);
                    if (pdfBytes != null)
                    {
                        bigWebApps.bigWebDesk.Data.FileItem[] _files = new bigWebApps.bigWebDesk.Data.FileItem[1];
                        _files[0] = new bigWebApps.bigWebDesk.Data.FileItem(0, filename, pdfBytes.Length, DateTime.Now, string.Empty, pdfBytes);
                        _mail_notification.AttachedFiles = _files;
                    }
                    string _return_string = _mail_notification.Commit(true);
                }
                catch
                {
                    throw new HttpError(HttpStatusCode.NotFound, "Email error.");
                }
            }
            else
            {
                throw new HttpError(HttpStatusCode.NotFound, "No recepients selected.");
            }
            return(invoice);
        }