Inheritance: IAttachmentTarget
示例#1
0
文件: Jobs.cs 项目: garysharp/Disco
        public static PublishJobResult Publish(DiscoDataContext Database, Job Job, User TechUser, string Recipient, string RecipientReference, string Comments, List<JobAttachment> Attachments, Func<JobAttachment, DiscoDataContext, string> AttachmentFilenameRetriever)
        {
            var url = ServiceUrl("Publish");

            using (var httpClient = new HttpClient())
            {
                using (var formData = new MultipartFormDataContent())
                {
                    formData.Add(new StringContent(Database.DiscoConfiguration.DeploymentId), "DeploymentId");
                    formData.Add(new StringContent(Job.Id.ToString()), "JobId");

                    formData.Add(new StringContent(TechUser.UserId), "TechnicianId");
                    formData.Add(new StringContent(TechUser.DisplayName ?? TechUser.UserId), "TechnicianName");
                    if (!string.IsNullOrWhiteSpace(TechUser.PhoneNumber))
                        formData.Add(new StringContent(TechUser.PhoneNumber), "TechnicianPhone");
                    if (!string.IsNullOrWhiteSpace(TechUser.EmailAddress))
                        formData.Add(new StringContent(TechUser.EmailAddress), "TechnicianEmail");

                    formData.Add(new StringContent(Recipient), "Recipient");
                    if (!string.IsNullOrWhiteSpace(RecipientReference))
                        formData.Add(new StringContent(RecipientReference), "RecipientReference");

                    if (!string.IsNullOrWhiteSpace(Comments))
                        formData.Add(new StringContent(Comments), "PublishedComments");

                    if (Attachments != null && Attachments.Count > 0)
                    {
                        Attachments
                            .Select(a => new { Attachment = a, Filename = AttachmentFilenameRetriever(a, Database) })
                            .Where(a => System.IO.File.Exists(a.Filename))
                            .Select((a, i) => new { Attachment = a.Attachment, Filename = a.Filename, Index = i })
                            .ToList()
                            .ForEach(a =>
                            {
                                formData.Add(new StringContent(a.Attachment.Filename), string.Format("Attachments[{0}].Filename", a.Index));
                                formData.Add(new StringContent(a.Attachment.MimeType), string.Format("Attachments[{0}].MimeType", a.Index));
                                formData.Add(new StringContent(a.Attachment.Timestamp.ToISO8601()), string.Format("Attachments[{0}].CreatedDate", a.Index));
                                if (a.Attachment.DocumentTemplateId != null)
                                    formData.Add(new StringContent(a.Attachment.DocumentTemplateId), string.Format("Attachments[{0}].DocumentTemplateId", a.Index));
                                if (a.Attachment.Comments != null)
                                    formData.Add(new StringContent(a.Attachment.Comments), string.Format("Attachments[{0}].Comments", a.Index));

                                formData.Add(new ByteArrayContent(File.ReadAllBytes(a.Filename)), string.Format("Attachments[{0}].File", a.Index), a.Attachment.Filename);
                            });
                    }

                    var response = httpClient.PostAsync(url, formData).Result;

                    response.EnsureSuccessStatusCode();

                    var resultJson = response.Content.ReadAsStringAsync().Result;
                    var result = JsonConvert.DeserializeObject<PublishJobResult>(resultJson);

                    return result;
                }
            }
        }
示例#2
0
 public static FileImageExpressionResult JobAttachmentLastImage(Job Job, DiscoDataContext Database)
 {
     var attachment = Job.JobAttachments.LastOrDefault(ja => ja.MimeType.StartsWith("image/", StringComparison.OrdinalIgnoreCase));
     if (attachment != null)
     {
         var filename = attachment.RepositoryFilename(Database);
         return new FileImageExpressionResult(filename);
     }
     else
         return null;
 }
示例#3
0
        public static FileMontageImageExpressionResult JobAttachmentImageMontage(Job Job, DiscoDataContext Database)
        {
            if (Job == null)
                throw new ArgumentNullException("Job");
            if (Job.JobAttachments == null)
                throw new ArgumentException("Job.JobAttachments is null", "Job");

            var attachments = Job.JobAttachments.Where(a => a.MimeType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)).ToList();

            if (attachments.Count > 0)
            {
                var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(Database)).ToList();

                return new FileMontageImageExpressionResult(attachmentFilepaths);
            }
            else
                return null;
        }
示例#4
0
 public static string JobStatusDescription(string StatusId, Job j = null)
 {
     switch (StatusId)
     {
         case Job.JobStatusIds.Open:
             return "Open";
         case Job.JobStatusIds.Closed:
             return "Closed";
         case Job.JobStatusIds.AwaitingWarrantyRepair:
             if (j == null)
                 return "Awaiting Warranty Repair";
             else
                 if (j.DeviceHeld.HasValue)
                     return string.Format("Awaiting Warranty Repair ({0})", j.JobMetaWarranty.ExternalName);
                 else
                     return string.Format("Awaiting Warranty Repair - Not Held ({0})", j.JobMetaWarranty.ExternalName);
         case Job.JobStatusIds.AwaitingRepairs:
             if (j == null)
                 return "Awaiting Repairs";
             else
                 if (j.DeviceHeld.HasValue)
                     return string.Format("Awaiting Repairs ({0})", j.JobMetaNonWarranty.RepairerName);
                 else
                     return string.Format("Awaiting Repairs - Not Held ({0})", j.JobMetaNonWarranty.RepairerName);
         case Job.JobStatusIds.AwaitingDeviceReturn:
             return "Awaiting Device Return";
         case Job.JobStatusIds.AwaitingUserAction:
             return "Awaiting User Action";
         case Job.JobStatusIds.AwaitingAccountingPayment:
             return "Awaiting Accounting Payment";
         case Job.JobStatusIds.AwaitingAccountingCharge:
             return "Awaiting Accounting Charge";
         case Job.JobStatusIds.AwaitingInsuranceProcessing:
             return "Awaiting Insurance Processing";
         default:
             return "Unknown";
     }
 }
示例#5
0
文件: Jobs.cs 项目: garysharp/Disco
        public static PublishJobResult UpdateRecipientReference(DiscoDataContext Database, Job Job, int PublishedJobId, string PublishedJobSecret, string RecipientReference)
        {
            var url = ServiceUrl("UpdateRecipientReference");

            using (var httpClient = new HttpClient())
            {
                using (var formData = new FormUrlEncodedContent(new KeyValuePair<string, string>[] {
                    new KeyValuePair<string, string>("PublishedJobId", PublishedJobId.ToString()),
                    new KeyValuePair<string, string>("PublishedJobSecret", PublishedJobSecret),
                    new KeyValuePair<string, string>("RecipientReference", RecipientReference)
                }))
                {
                    var response = httpClient.PostAsync(url, formData).Result;

                    response.EnsureSuccessStatusCode();

                    var resultJson = response.Content.ReadAsStringAsync().Result;
                    var result = JsonConvert.DeserializeObject<PublishJobResult>(resultJson);

                    return result;
                }
            }
        }
        private void SubmitJobValidateEnvironment(DiscoDataContext dbContext, Controller controller, User TechUser, Job Job, ViewModels.NNOptionsViewModel OptionsModel)
        {
            // Validate TechUser Email Address
            if (OptionsModel == null || (OptionsModel.NTPDevice.HasValue && !OptionsModel.NTPDevice.Value))
            {
                // Non-NTP Device (or Unknown)
                // Check for Technicians Details
                if (string.IsNullOrEmpty(TechUser.EmailAddress))
                    controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Email Address (Update your Email Address in Active Directory)");
                if (string.IsNullOrEmpty(TechUser.PhoneNumber))
                    controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Phone Number (Update your Telephone Number in Active Directory)");
            }
            else
            {
                if (!NNSuspectedIssues.ContainsKey(OptionsModel.Issue))
                    controller.ModelState.AddModelError("Issue", "Unknown Suspected Issue Id");

                if (OptionsModel.NTPDevice.HasValue && OptionsModel.NTPDevice.Value)
                {
                    // NTP Device (Use Users Details)
                    if (string.IsNullOrEmpty(Job.User.EmailAddress))
                        controller.ModelState.AddModelError(string.Empty, "NN NTP Device requires the User's Email Address (Update the Email Address in Active Directory)");
                    if (string.IsNullOrEmpty(Job.User.PhoneNumber))
                        controller.ModelState.AddModelError(string.Empty, "NN NTP Device requires the User's Phone Number (Update the Phone Number in Active Directory)");
                }
                else
                {
                    // Non-NTP Device (or Unknown)
                    // Check for Technicians Details
                    if (string.IsNullOrEmpty(TechUser.EmailAddress))
                        controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Email Address (Update your Email Address in Active Directory)");
                    if (string.IsNullOrEmpty(TechUser.PhoneNumber))
                        controller.ModelState.AddModelError(string.Empty, "NN Requires a Technician Phone Number (Update your Telephone Number in Active Directory)");
                }
            }
        }
示例#7
0
 private void UpdateExpectedClosedDate(Job job, string ExpectedClosedDate)
 {
     if (!string.IsNullOrEmpty(ExpectedClosedDate))
     {
         DateTime ecd;
         if (DateTime.TryParse(ExpectedClosedDate, out ecd))
         {
             ecd = job.ValidateDateAfterOpened(ecd);
             job.ExpectedClosedDate = ecd;
         }
         else
         {
             throw new Exception("Invalid Date Format");
         }
     }
     else
     {
         job.ExpectedClosedDate = null;
     }
     Database.SaveChanges();
 }
示例#8
0
        private void UpdateWarrantyExternalName(Job job, string ExternalName)
        {
            // Validate Is Warranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware Warranty Jobs");
            }

            if (string.IsNullOrWhiteSpace(ExternalName))
            {
                job.JobMetaWarranty.ExternalName = null;
            }
            else
            {
                job.JobMetaWarranty.ExternalName = ExternalName.Trim();
            }
            Database.SaveChanges();
        }
示例#9
0
        private void UpdateWarrantyExternalLoggedDate(Job job, string ExternalLoggedDate)
        {
            // Validate Is Warranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware Warranty Jobs");
            }

            if (string.IsNullOrEmpty(ExternalLoggedDate))
            {
                job.JobMetaWarranty.ExternalLoggedDate = null;
            }
            else
            {
                DateTime d;
                if (DateTime.TryParse(ExternalLoggedDate, out d))
                {
                    job.JobMetaWarranty.ExternalLoggedDate = d;
                }
                else
                {
                    throw new Exception("Invalid Date Format");
                }
            }
            Database.SaveChanges();
        }
示例#10
0
        private void UpdateInsuranceEventLocation(Job job, string EventLocation)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrWhiteSpace(EventLocation))
            {
                job.JobMetaInsurance.EventLocation = null;
            }
            else
            {
                job.JobMetaInsurance.EventLocation = EventLocation.Trim();
            }
            Database.SaveChanges();
        }
示例#11
0
        private void UpdateInsuranceLossOrDamageDate(Job job, string LossOrDamageDate)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrEmpty(LossOrDamageDate))
            {
                job.JobMetaInsurance.LossOrDamageDate = null;
            }
            else
            {
                DateTime d;
                if (DateTime.TryParse(LossOrDamageDate, out d))
                {
                    job.JobMetaInsurance.LossOrDamageDate = d;
                }
                else
                {
                    throw new Exception("Invalid Date Format");
                }
            }
            Database.SaveChanges();
        }
示例#12
0
 public abstract Dictionary<string, string> SubmitJobDiscloseInfo(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription, Dictionary<string, string> WarrantyProviderProperties);
示例#13
0
        private void UpdateInsuranceThirdPartyCaused(Job job, string ThirdPartyCaused)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            bool b;
            if (string.IsNullOrEmpty(ThirdPartyCaused) || !bool.TryParse(ThirdPartyCaused, out b))
            {
                throw new Exception("Invalid Boolean Value");
            }

            job.JobMetaInsurance.ThirdPartyCaused = b;
            Database.SaveChanges();
        }
示例#14
0
        private void UpdateNonWarrantyRepairerReference(Job job, string RepairerReference)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrWhiteSpace(RepairerReference))
            {
                job.JobMetaNonWarranty.RepairerReference = null;
            }
            else
            {
                job.JobMetaNonWarranty.RepairerReference = RepairerReference.Trim();
            }
            Database.SaveChanges();
        }
示例#15
0
        private Models.Job._DateChangeModel UpdateInsuranceClaimFormSentDate(Job job, string ClaimFormSentDate)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrEmpty(ClaimFormSentDate))
            {
                job.JobMetaInsurance.ClaimFormSentDate = null;
            }
            else
            {
                if (ClaimFormSentDate.Equals("Now", StringComparison.OrdinalIgnoreCase))
                {
                    job.JobMetaInsurance.ClaimFormSentDate = DateTime.Now;
                }
                else
                {
                    DateTime d;
                    if (DateTime.TryParse(ClaimFormSentDate, out d))
                    {
                        d = job.ValidateDateAfterOpened(d);
                        job.JobMetaInsurance.ClaimFormSentDate = d;
                    }
                    else
                    {
                        throw new Exception("Invalid Date Format");
                    }
                }
            }
            job.JobMetaInsurance.ClaimFormSentUserId = CurrentUser.UserId;
            Database.SaveChanges();
            return new Models.Job._DateChangeModel()
            {
                Id = job.Id,
                Result = "OK",
                UserDescription = CurrentUser.ToString()
            }.SetDateTime(job.JobMetaInsurance.ClaimFormSentDate);
        }
示例#16
0
 /// <summary>
 /// Called when a job repair information is shown. Allows a plugin to inject a View to display additional information.
 /// </summary>
 /// <returns>A Tuple consisting of the Razor View type and a View Model</returns>
 public virtual Tuple<Type, dynamic> JobDetails(DiscoDataContext Database, Controller controller, Job Job)
 {
     return null;
 } 
示例#17
0
        private void UpdateNonWarrantyIsInsuranceClaim(Job job, string IsInsuranceClaim)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }
            bool bIsInsuranceClaim;
            if (string.IsNullOrEmpty(IsInsuranceClaim) || !bool.TryParse(IsInsuranceClaim, out bIsInsuranceClaim))
            {
                throw new Exception("Invalid IsInsuranceClaim Value");
            }

            job.JobMetaNonWarranty.IsInsuranceClaim = bIsInsuranceClaim;
            if (job.JobMetaInsurance == null)
            {
                var jmi = new Disco.Models.Repository.JobMetaInsurance();
                jmi.JobId = job.Id;

                if (job.Device.DeviceBatch != null)
                {
                    jmi.DateOfPurchase = job.Device.DeviceBatch.PurchaseDate;
                }
                else
                {
                    if (!string.IsNullOrEmpty(job.DeviceSerialNumber))
                    {
                        jmi.DateOfPurchase = job.Device.DeviceModel.DefaultPurchaseDate;
                    }
                }
                if (job.User != null)
                    jmi.OtherInterestedParties = job.User.DisplayName;

                job.JobMetaInsurance = jmi;
                Database.JobMetaInsurances.Add(jmi);
            }
            Database.SaveChanges();
        }
示例#18
0
 /// <summary>
 /// Called when the plugin should submit the job to the external party.
 /// </summary>
 /// <returns>A reference number/identifier from the external party which is stored in <see cref="Disco.Models.Repository.RepairerReference"/></returns>
 public abstract string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription, Dictionary<string, string> ProviderProperties);
示例#19
0
 /// <summary>
 /// Called after the RepairDescription is completed and allows the plugin to parse any data collected from SubmitJobBegin.
 /// </summary>
 /// <returns>A Dictionary of key/value items which are persisted throughout the submission and passed into the final SubmitJob method.</returns>
 public virtual Dictionary<string, string> SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription)
 {
     return null;
 }
示例#20
0
 /// <summary>
 /// Called when a user selects this plugin to repair and allows a plugin to inject a View to collect additional information.
 /// </summary>
 /// <returns>A Tuple consisting of the Razor View type and a View Model</returns>
 public virtual Tuple<Type, dynamic> SubmitJobBegin(DiscoDataContext Database, Controller controller, Job Job, OrganisationAddress Address, User TechUser)
 {
     return null;
 }
示例#21
0
        private void UpdateDeviceHeldLocation(Job job, string DeviceHeldLocation)
        {
            if (!string.IsNullOrWhiteSpace(DeviceHeldLocation) &&
                Database.DiscoConfiguration.JobPreferences.LocationMode == LocationModes.RestrictedList)
            {
                // Enforce Restricted List Mode
                var value = DeviceHeldLocation.Trim();

                if (!Database.DiscoConfiguration.JobPreferences.LocationList.Contains(value, StringComparer.OrdinalIgnoreCase))
                    throw new ArgumentException("The location was not found in the list (Mode: Restricted List)");
            }

            if (string.IsNullOrWhiteSpace(DeviceHeldLocation))
                job.DeviceHeldLocation = null;
            else
                job.DeviceHeldLocation = DeviceHeldLocation.Trim();

            Database.SaveChanges();
        }
示例#22
0
 public abstract Dictionary<string, string> SubmitJobParseProperties(DiscoDataContext Database, FormCollection form, Controller controller, Job Job, OrganisationAddress Address, User TechUser, string FaultDescription);
示例#23
0
        private void UpdateFlags(Job job, string Flags)
        {
            // Only User Management Job Supports Flags at the moment
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.UMgmt, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for User Management Jobs");
            }

            if (string.IsNullOrWhiteSpace(Flags))
            {
                if (!job.Flags.HasValue)
                {
                    job.Flags = null;
                    Database.SaveChanges();
                }
            }
            else
            {
                long flags;
                if (Flags.Contains(','))
                {
                    flags = 0;
                    foreach (var fs in Flags.Split(','))
                    {
                        long fi;
                        if (!long.TryParse(fs, out fi))
                            throw new Exception("Invalid Int64 Format");
                        else
                            flags = flags | fi;
                    }
                }
                else
                {
                    if (!long.TryParse(Flags, out flags))
                        throw new Exception("Invalid Int64 Format");
                }
                if (flags == 0)
                {
                    if (job.Flags.HasValue)
                    {
                        job.Flags = null;
                        Database.SaveChanges();
                    }
                }
                else
                {
                    if (!job.Flags.HasValue || (long)job.Flags.Value != flags)
                    {
                        job.Flags = (Disco.Models.Repository.Job.UserManagementFlags)flags;
                        Database.SaveChanges();
                    }
                }
            }
        }
示例#24
0
 public abstract dynamic JobDetailsViewModel(DiscoDataContext Database, Controller controller, Job Job);
示例#25
0
        private void UpdateNonWarrantyPurchaseOrderReference(Job job, string PurchaseOrderReference)
        {
            if (string.IsNullOrWhiteSpace(PurchaseOrderReference))
                job.JobMetaNonWarranty.PurchaseOrderReference = null;
            else
                job.JobMetaNonWarranty.PurchaseOrderReference = PurchaseOrderReference;

            Database.SaveChanges();
        }
示例#26
0
        private void UpdateInsurancePoliceNotifiedCrimeReportNo(Job job, string PoliceNotifiedCrimeReportNo)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrWhiteSpace(PoliceNotifiedCrimeReportNo))
            {
                job.JobMetaInsurance.PoliceNotifiedCrimeReportNo = null;
            }
            else
            {
                job.JobMetaInsurance.PoliceNotifiedCrimeReportNo = PoliceNotifiedCrimeReportNo.Trim();
            }
            Database.SaveChanges();
        }
示例#27
0
        private void UpdateNonWarrantyRepairerCompletedDate(Job job, string RepairerCompletedDate)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrEmpty(RepairerCompletedDate))
            {
                job.JobMetaNonWarranty.RepairerCompletedDate = null;
            }
            else
            {
                if (RepairerCompletedDate.Equals("Now", StringComparison.OrdinalIgnoreCase))
                {
                    job.JobMetaNonWarranty.RepairerCompletedDate = DateTime.Now;
                }
                else
                {
                    DateTime d;
                    if (DateTime.TryParse(RepairerCompletedDate, out d))
                    {
                        job.JobMetaNonWarranty.RepairerCompletedDate = d;
                    }
                    else
                    {
                        throw new Exception("Invalid Date Format");
                    }
                }
            }
            Database.SaveChanges();
        }
示例#28
0
        private void UpdateInsurancePoliceNotifiedDate(Job job, string PoliceNotifiedDate)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrEmpty(PoliceNotifiedDate))
            {
                job.JobMetaInsurance.PoliceNotifiedDate = null;
            }
            else
            {
                DateTime dt;
                if (!DateTime.TryParse(PoliceNotifiedDate, out dt))
                {
                    throw new Exception("Invalid DateTime Value");
                }
                job.JobMetaInsurance.PoliceNotifiedDate = dt;
            }
            Database.SaveChanges();
        }
示例#29
0
文件: Jobs.cs 项目: garysharp/Disco
        public static Job Create(DiscoDataContext Database, Device device, User user, JobType type, List<JobSubType> subTypes, User initialTech, bool addAutoQueues = true)
        {
            Job j = new Job()
            {
                JobType = type,
                OpenedTechUserId = initialTech.UserId,
                OpenedTechUser = initialTech,
                OpenedDate = DateTime.Now
            };

            // Device
            if (device != null)
            {
                j.Device = device;
                j.DeviceSerialNumber = device.SerialNumber;
            }

            // User
            if (user != null)
            {
                j.User = user;
                j.UserId = user.UserId;
            }

            // Sub Types
            List<JobSubType> jobSubTypes = subTypes.ToList();
            j.JobSubTypes = jobSubTypes;

            Database.Jobs.Add(j);

            // Job Queues
            if (addAutoQueues)
            {
                var queues = from st in subTypes
                             from jq in st.JobQueues
                             group st by jq into g
                             select new { queue = g.Key, subTypes = g };
                foreach (var queue in queues)
                {
                    var commentBuilder = new StringBuilder("Automatically added by:").AppendLine();
                    foreach (var subType in queue.subTypes)
                    {
                        commentBuilder.AppendLine().Append("* ").Append(subType.Description);
                    }

                    var jqj = new JobQueueJob()
                    {
                        JobQueueId = queue.queue.Id,
                        Job = j,
                        AddedDate = DateTime.Now,
                        AddedUserId = initialTech.UserId,
                        AddedComment = commentBuilder.ToString(),
                        SLAExpiresDate = queue.queue.DefaultSLAExpiry.HasValue ? (DateTime?)DateTime.Now.AddMinutes(queue.queue.DefaultSLAExpiry.Value) : null,
                        Priority = JobQueuePriority.Normal
                    };

                    Database.JobQueueJobs.Add(jqj);
                }
            }

            switch (type.Id)
            {
                case JobType.JobTypeIds.HWar:
                    Database.JobMetaWarranties.Add(new JobMetaWarranty() { Job = j });
                    break;
                case JobType.JobTypeIds.HNWar:
                    Database.JobMetaNonWarranties.Add(new JobMetaNonWarranty() { Job = j });
                    if (device != null)
                    {
                        // Add Job Components
                        var components = Database.DeviceComponents.Include("JobSubTypes").Where(c => !c.DeviceModelId.HasValue || c.DeviceModelId == j.Device.DeviceModelId);
                        var addedComponents = new List<DeviceComponent>();
                        foreach (var c in components)
                        {
                            if (c.JobSubTypes.Count == 0)
                            { // No Filter
                                addedComponents.Add(c);
                            }
                            else
                            {
                                foreach (var st in c.JobSubTypes)
                                {
                                    foreach (var jst in jobSubTypes)
                                    {
                                        if (st.JobTypeId == jst.JobTypeId && st.Id == jst.Id)
                                        {
                                            addedComponents.Add(c);
                                            break;
                                        }
                                    }
                                    if (addedComponents.Contains(c))
                                        break;
                                }
                            }
                        }
                        foreach (var c in addedComponents)
                            Database.JobComponents.Add(new JobComponent()
                            {
                                Job = j,
                                TechUserId = initialTech.UserId,
                                Cost = c.Cost,
                                Description = c.Description
                            });
                    }
                    break;
            }

            return j;
        }
示例#30
0
        private void UpdateInsuranceBurglaryTheftMethodOfEntry(Job job, string BurglaryTheftMethodOfEntry)
        {
            // Validate Is NonWarranty Job
            if (!job.JobTypeId.Equals(JobType.JobTypeIds.HNWar, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("This property can only be set for Hardware NonWarranty Jobs");
            }

            if (string.IsNullOrWhiteSpace(BurglaryTheftMethodOfEntry))
            {
                job.JobMetaInsurance.BurglaryTheftMethodOfEntry = null;
            }
            else
            {
                job.JobMetaInsurance.BurglaryTheftMethodOfEntry = BurglaryTheftMethodOfEntry.Trim();
            }
            Database.SaveChanges();
        }