Beispiel #1
0
        // GET: CompanyEmailTemplate
        public ActionResult Index(int?companyId)
        {
            // SelectListItem
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            string _userId    = User.Identity.GetUserId();
            int    _companyId = 0;
            var    _companies = GetUsersCompanies(_userId);

            if (_companies != null && _companies.Length > 0)
            {
                int _index = 0;
                if (companyId.HasValue)
                {
                    _index = Array.FindIndex <SelectListItem>(_companies, x => x.Value == companyId.Value.ToString());
                    if (_index < 0)
                    {
                        _index = 0;
                    }
                }
                _companyId = Convert.ToInt32(_companies[_index].Value);
                _companies[_index].Selected = true;
            }
            CompanyEmailTemplate _viewModel = new CompanyEmailTemplate()
            {
                CompanySelect    = _companies.ToList(),
                CompanyTemplates = _access.ListByCompany(_companyId)
            };
            var emailTemplates = db.EmailTemplates.Include(e => e.Company).Include(e => e.IncidentType);

            return(View(_viewModel));
        }
Beispiel #2
0
        public ActionResult DeleteConfirmed(int?companyId, int?incidentTypeId)
        {
            if (!companyId.HasValue || !incidentTypeId.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!IsValidCompany(companyId.Value))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);

            _access.Delete(companyId.Value, incidentTypeId.Value);
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        //
        /// <summary>
        /// GET: CompanyEmailTemplate/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int?companyId, int?incidentTypeId)
        {
            if (!companyId.HasValue || !incidentTypeId.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!IsValidCompany(companyId.Value))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(companyId.Value, incidentTypeId.Value);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            return(View(_row));
        }
Beispiel #4
0
        //
        // GET: CompanyEmailTemplate/Edit/5
        public ActionResult Edit(int?companyId, int?incidentTypeId)
        {
            if (!companyId.HasValue || !incidentTypeId.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!IsValidCompany(companyId.Value))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(companyId.Value, incidentTypeId.Value);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId      = new SelectList(db.Companies, "CompanyId", "CompanyShortName", _row.CompanyId);
            ViewBag.IncidentTypeId = new SelectList(db.IncidentTypes, "IncidentTypeId", "IncidentTypeShortDesc", _row.IncidentTypeId);
            return(View(_row));
        }
Beispiel #5
0
        public ActionResult Edit([Bind(Include = "CompanyId,IncidentTypeId,SubjectLine,EmailBody,TimeTemplate,ThanksTemplate,LogTemplate,Template,FromServer")] EmailTemplate emailTemplate)
        {
            if (ModelState.IsValid)
            {
                if (!IsValidCompany(emailTemplate.CompanyId))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
                }
                db.Entry(emailTemplate).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(emailTemplate.CompanyId, emailTemplate.IncidentTypeId);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId      = new SelectList(db.Companies, "CompanyId", "CompanyShortName", emailTemplate.CompanyId);
            ViewBag.IncidentTypeId = new SelectList(db.IncidentTypes, "IncidentTypeId", "IncidentTypeShortDesc", emailTemplate.IncidentTypeId);
            return(View(_row));
        }