示例#1
0
        public virtual ActionResult LogWarranty(Models.Job.LogWarrantyModel m, FormCollection form)
        {
            m.UpdateModel(Database, true);

            if (ModelState.IsValid)
            {
                switch (m.SubmissionAction)
                {
                    case "Update":
                        var updatedModel = new Models.Job.LogWarrantyModel()
                        {
                            JobId = m.JobId,
                            WarrantyProviderId = m.WarrantyProviderId,
                            OrganisationAddressId = m.OrganisationAddressId,
                            FaultDescription = m.FaultDescription,
                            PublishAttachmentIds = m.PublishAttachmentIds,
                            PublishAttachments = m.PublishAttachments
                        };
                        updatedModel.UpdateModel(Database, false);

                        if (updatedModel.WarrantyProvider != null)
                        {
                            using (var wp = updatedModel.WarrantyProvider.CreateInstance<WarrantyProviderFeature>())
                            {
                                if (wp.SubmitJobViewType != null)
                                {
                                    updatedModel.WarrantyProviderSubmitJobViewType = wp.SubmitJobViewType;
                                    updatedModel.WarrantyProviderSubmitJobModel = wp.SubmitJobViewModel(Database, this, updatedModel.Job, updatedModel.OrganisationAddress, updatedModel.TechUser);
                                }
                            }
                        }

                        return View(updatedModel);
                    case "Manual":
                        if (string.IsNullOrWhiteSpace(m.ManualProviderName))
                        {
                            ModelState.AddModelError("ManualProviderName", "The Warranty Provider Name is required");
                            return View(Views.LogWarranty, m);
                        }
                        try
                        {
                            m.Job.OnLogWarranty(Database, m.FaultDescription, m.ManualProviderName, m.ManualProviderReference, m.OrganisationAddress, m.TechUser);
                            Database.SaveChanges();
                            return RedirectToAction(MVC.Job.Show(m.JobId));
                        }
                        catch (Exception ex)
                        {
                            ex.ToExceptionless().Submit();
                            m.Error = ex;
                            return View(Views.LogWarrantyError, m);
                            throw;
                        }
                    case "Disclose":
                        using (var p = m.WarrantyProvider.CreateInstance<WarrantyProviderFeature>())
                        {
                            Dictionary<string, string> warrantyProviderProperties;
                            try
                            {
                                warrantyProviderProperties = p.SubmitJobParseProperties(Database, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription);
                            }
                            catch (Exception ex)
                            {
                                ex.ToExceptionless().Submit();
                                m.Error = ex;
                                return View(Views.LogWarrantyError, m);
                            }
                            if (!ModelState.IsValid)
                                return View(Views.LogWarranty, m);

                            if (warrantyProviderProperties != null)
                            {
                                m.ProviderPropertiesJson = JsonConvert.SerializeObject(warrantyProviderProperties);
                            }
                            m.DiscloseProperties = p.SubmitJobDiscloseInfo(Database, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription, warrantyProviderProperties);
                            return View(Views.LogWarrantyDisclose, m);
                        }
                    case "Submit":
                        try
                        {
                            m.Job.OnLogWarranty(Database, m.FaultDescription, m.PublishAttachments, m.WarrantyProvider, m.OrganisationAddress, m.TechUser, m.ProviderProperties());
                            Database.SaveChanges();
                            return RedirectToAction(MVC.Job.Show(m.JobId));
                        }
                        catch (Exception ex)
                        {
                            ex.ToExceptionless().Submit();
                            m.Error = ex;
                            return View(Views.LogWarrantyError, m);
                            throw;
                        }
                    default:
                        return RedirectToAction(MVC.Job.Show(m.JobId));
                }

            }
            else
            {
                return View(Views.LogWarranty, m);
            }
        }
示例#2
0
        public virtual ActionResult LogWarranty(int id, string WarrantyProviderId, int? OrganisationAddressId)
        {
            var m = new Models.Job.LogWarrantyModel()
            {
                JobId = id,
                WarrantyProviderId = WarrantyProviderId,
                OrganisationAddressId = OrganisationAddressId
            };
            m.UpdateModel(Database, false);
            m.FaultDescription = m.Job.GenerateFaultDescription(Database);

            if (m.WarrantyProvider != null)
            {
                using (var wp = m.WarrantyProvider.CreateInstance<WarrantyProviderFeature>())
                {
                    if (wp.SubmitJobViewType != null)
                    {
                        m.WarrantyProviderSubmitJobViewType = wp.SubmitJobViewType;
                        m.WarrantyProviderSubmitJobModel = wp.SubmitJobViewModel(Database, this, m.Job, m.OrganisationAddress, m.TechUser);
                    }
                }
            }

            return View(m);
        }