Exemplo n.º 1
0
 public ActionResult Create(CompanyEmailTemplate companyEmailTemplate)
 {
     try
     {
         if (companyEmailTemplate != null)
         {
             if (companyEmailTemplate.Template != null)
             {
                 db.EmailTemplates.Add(companyEmailTemplate.Template);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             else
             {
                 Error("Company Email Template: empty."); // in BaseController
             }
         }
         else
         {
             Error("Company Email Template: empty view model."); // in BaseController
         }
     }
     catch (DbEntityValidationException _entityEx)
     {
         Base_AddErrors(_entityEx);
     }
     catch (Exception _ex)
     {
         Base_AddErrors(_ex);
     }
     return(View(CreateCreateViewModel(companyEmailTemplate.Template)));
 }
Exemplo n.º 2
0
        //
        CompanyEmailTemplate CreateCreateViewModel(EmailTemplate template)
        {
            string _userId = User.Identity.GetUserId();
            List <SelectListItem> _companies = GetUsersCompanies(_userId).ToList();
            var _sli = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Value = "", Text = "- Select a incident type- "
                }
            }.Union(new SelectList(db.IncidentTypes, "IncidentTypeId", "IncidentTypeShortDesc")).ToList();

            foreach (EmailTemplate _et in db.EmailTemplates)
            {
                _sli.Remove(_sli.Find(it => it.Value == _et.IncidentTypeId.ToString()));
            }
            JavaScriptSerializer _js_slzr = new JavaScriptSerializer();
            IncidentTypeAccess   _access  = new IncidentTypeAccess(db);
            string _itJsonString          = _js_slzr.Serialize(_access.List());
            //
            // ViewBag.CompanyId = _companies;
            // ViewBag.IncidentTypeId = _sli;
            // ViewBag.IncidentType = _itJsonString;
            CompanyEmailTemplate _viewModel = new CompanyEmailTemplate()
            {
                CompanySelect = _companies,
                // List<EmailTemplateData> CompanyTemplates;
                IncidentTypeSelect = _sli,
                IncidentTypeJson   = _itJsonString, // JSON string of array of IncidentType
                Template           = template
            };

            return(_viewModel);
        }