当前位置: 首页>>代码示例>>C#>>正文


C# Models.UpdateModel方法代码示例

本文整理汇总了C#中Models.UpdateModel方法的典型用法代码示例。如果您正苦于以下问题:C# Models.UpdateModel方法的具体用法?C# Models.UpdateModel怎么用?C# Models.UpdateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Models的用法示例。


在下文中一共展示了Models.UpdateModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogRepair

        public virtual ActionResult LogRepair(Models.Job.LogRepairModel m, FormCollection form)
        {
            m.UpdateModel(Database, true);

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

                        if (updatedModel.RepairProvider != null)
                        {
                            using (var wp = updatedModel.RepairProvider.CreateInstance<RepairProviderFeature>())
                            {
                                using (var rp = m.RepairProvider.CreateInstance<RepairProviderFeature>())
                                {
                                    m.RepairProviderSubmitJobBeginResult = rp.SubmitJobBegin(Database, this, updatedModel.Job, updatedModel.OrganisationAddress, updatedModel.TechUser);
                                }
                            }
                        }

                        return View(updatedModel);
                    case "Manual":
                        if (string.IsNullOrWhiteSpace(m.ManualProviderName))
                        {
                            ModelState.AddModelError("ManualProviderName", "The Repair Provider Name is required");
                            return View(Views.LogRepair, m);
                        }
                        try
                        {
                            m.Job.OnLogRepair(Database, m.RepairDescription, 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.LogRepairError, m);
                            throw;
                        }
                    case "Disclose":
                        using (var p = m.RepairProvider.CreateInstance<RepairProviderFeature>())
                        {
                            Dictionary<string, string> warrantyProviderProperties;
                            try
                            {
                                warrantyProviderProperties = p.SubmitJobParseProperties(Database, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.RepairDescription);
                            }
                            catch (Exception ex)
                            {
                                ex.ToExceptionless().Submit();
                                m.Error = ex;
                                return View(Views.LogRepairError, m);
                            }
                            if (!ModelState.IsValid)
                                return View(Views.LogRepair, m);

                            if (warrantyProviderProperties != null)
                            {
                                m.ProviderPropertiesJson = JsonConvert.SerializeObject(warrantyProviderProperties);
                            }
                            m.DiscloseProperties = p.SubmitJobDiscloseInfo(Database, m.Job, m.OrganisationAddress, m.TechUser, m.RepairDescription, warrantyProviderProperties);
                            return View(Views.LogRepairDisclose, m);
                        }
                    case "Submit":
                        try
                        {
                            m.Job.OnLogRepair(Database, m.RepairDescription, m.PublishAttachments, m.RepairProvider, 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.LogRepairError, m);
                            throw;
                        }
                    default:
                        return RedirectToAction(MVC.Job.Show(m.JobId));
                }

            }
            else
            {
                return View(Views.LogRepair, m);
            }
        }
开发者ID:garysharp,项目名称:Disco,代码行数:99,代码来源:JobController.cs

示例2: Create

        public virtual ActionResult Create(Models.DocumentTemplate.CreateModel model)
        {
            model.UpdateModel(Database);

            if (ModelState.IsValid)
            {
                // Check for Existing
                var existing = Database.DocumentTemplates.Where(m => m.Id == model.DocumentTemplate.Id).FirstOrDefault();
                if (existing == null)
                {

                    Database.DocumentTemplates.Add(model.DocumentTemplate);

                    if (model.DocumentTemplate.Scope == Disco.Models.Repository.DocumentTemplate.DocumentTemplateScopes.Job)
                    {
                        var jobSubTypes = new List<Disco.Models.Repository.JobSubType>();
                        jobSubTypes.AddRange(model.GetJobSubTypes);
                        model.DocumentTemplate.JobSubTypes = jobSubTypes;
                        //foreach (var jobSubType in model.GetJobSubTypes)
                        //    model.AttachmentType.JobSubTypes.Add(jobSubType);
                    }

                    Database.SaveChanges();

                    // Save Template
                    model.DocumentTemplate.SavePdfTemplate(Database, model.Template.InputStream);

                    return RedirectToAction(MVC.Config.DocumentTemplate.Index(model.DocumentTemplate.Id));
                }
                else
                {
                    ModelState.AddModelError("Id", "A Document Template with this Id already exists.");
                }
            }

            // UI Extensions
            UIExtensions.ExecuteExtensions<ConfigDocumentTemplateCreateModel>(this.ControllerContext, model);

            return View(model);
        }
开发者ID:garysharp,项目名称:Disco,代码行数:40,代码来源:DocumentTemplateController.cs

示例3: Create

        public virtual ActionResult Create(Models.Job.CreateModel m)
        {
            m.UpdateModel(Database, Authorization);

            if (!ModelState.IsValid)
            {
                // UI Extensions
                UIExtensions.ExecuteExtensions<JobCreateModel>(this.ControllerContext, m);

                return View(m);
            }
            else
            {
                Database.Configuration.LazyLoadingEnabled = true;

                // Create New Job
                var currentUser = Database.Users.Find(UserService.CurrentUserId);

                // Try QuickLog?
                bool addAutoQueues = !(Authorization.Has(Claims.Job.Actions.Close)
                    && m.QuickLog.HasValue && m.QuickLog.Value
                    && m.QuickLogTaskTimeMinutes.HasValue && m.QuickLogTaskTimeMinutes.Value > 0);

                var j = Jobs.Create(Database, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser, addAutoQueues);

                if (m.DeviceHeld.Value)
                {
                    j.OnDeviceHeld(currentUser);
                    m.QuickLog = false;
                }
                else
                {
                    if (Authorization.Has(Claims.Job.Actions.Close)
                        && m.QuickLog.HasValue && m.QuickLog.Value
                        && m.QuickLogTaskTimeMinutes.HasValue && m.QuickLogTaskTimeMinutes.Value > 0
                        && (j.JobQueues == null || j.JobQueues.All(jqj => jqj.RemovedDate.HasValue))
                        )
                    {
                        // Quick Log
                        // Set Opened Date in the past
                        j.OpenedDate = DateTime.Now.AddMinutes(-1 * m.QuickLogTaskTimeMinutes.Value);
                        // Close Job
                        j.OnCloseNormally(Database, currentUser);
                    }
                    else
                    {
                        m.QuickLog = false;
                    }
                }

                Database.SaveChanges();

                // Evaluate OnCreate Expression
                try
                {
                    var onCreateResult = j.EvaluateOnCreateExpression(Database);
                    if (!string.IsNullOrWhiteSpace(onCreateResult))
                    {
                        var jl = new JobLog()
                        {
                            Job = j,
                            TechUser = currentUser,
                            Timestamp = DateTime.Now,
                            Comments = onCreateResult
                        };
                        Database.JobLogs.Add(jl);
                    }
                }
                catch (Exception ex)
                {
                    SystemLog.LogException("Job Expression - OnCreateExpression", ex);
                }


                // Add Comments
                if (!string.IsNullOrWhiteSpace(m.Comments))
                {
                    var jl = new JobLog()
                    {
                        Job = j,
                        TechUser = currentUser,
                        Timestamp = DateTime.Now,
                        Comments = m.Comments
                    };
                    Database.JobLogs.Add(jl);
                }

                Database.SaveChanges();

                // Return Dialog Redirect
                var redirectModel = new Models.Job.CreateRedirectModel()
                {
                    JobId = j.Id
                };
                redirectModel.RedirectDelay = TimeSpan.FromSeconds(2);
                if (m.QuickLog.HasValue && m.QuickLog.Value && !string.IsNullOrWhiteSpace(m.SourceUrl))
                    redirectModel.RedirectLink = m.SourceUrl;
                else if (!Authorization.Has(Claims.Job.Show))
                    if (!string.IsNullOrWhiteSpace(m.SourceUrl))
                        redirectModel.RedirectLink = m.SourceUrl;
//.........这里部分代码省略.........
开发者ID:garysharp,项目名称:Disco,代码行数:101,代码来源:JobController.cs


注:本文中的Models.UpdateModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。