public async Task <ActionResult> Edit(EditNotificationTemplateModel model)
        {
            if (ModelState.IsValid)
            {
                List <string> ListA, ParamList;// = new List<string>();
                ListA     = new List <string>();
                ParamList = new List <string>();
                if (model.enableEmail)
                {
                    ParamList = ParamList.Union(ListA).ToList();
                    if (model.TemplateSubject != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(model.TemplateSubject)).ToList();
                    }
                    if (model.TemplateMessage != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(model.TemplateMessage)).ToList();
                    }
                }
                if (model.enableSMSMessage)
                {
                    if (model.SMSMessage != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(model.SMSMessage)).ToList();
                    }
                }
                if (model.enableWebMessage)
                {
                    if (model.WebMessage != null && model.WebNotifyLink != null)
                    {
                        ParamList = ParamList.Union(ParameterListing(model.WebMessage)).ToList();
                        ParamList = ParamList.Union(ParameterListing(model.WebNotifyLink)).ToList();
                    }
                }

                model.ParameterList   = ParamList;
                model.TemplateMessage = Server.HtmlEncode(model.TemplateMessage);
                var response = await WepApiMethod.SendApiAsync <EditNotificationTemplateModel>(HttpVerbs.Put, $"Template/Email?id={model.Id}", model);

                if (response.isSuccess)
                {
                    //aiman edit
                    await LogActivity(Modules.Setting, "Update Notification Template");

                    TempData["SuccessMessage"] = "Notification Template updated successfully";

                    return(RedirectToAction("Details", "EmailTemplates", new { area = "Template", @id = model.Id }));
                }
                else
                {
                    TempData["ErrorMessage"] = "Failed to update Notification Template";
                    return(RedirectToAction("Details", "EmailTemplates", new { area = "Template", @id = model.Id }));
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Failed to update Notification Template";
                return(RedirectToAction("Details", "EmailTemplates", new { area = "Template", @id = model.Id }));
            }
        }
        // PUT: api/EmailTemplate/5
        public IHttpActionResult Put(int id, EditNotificationTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (id != model.Id)
            {
                return(BadRequest());
            }

            NotificationTemplate template = db.NotificationTemplates.Where(t => t.Id == id).FirstOrDefault();

            template.NotificationType     = model.NotificationType;
            template.NotificationCategory = model.NotificationCategory;
            template.TemplateName         = model.TemplateName;
            template.TemplateMessage      = model.TemplateMessage;
            template.TemplateSubject      = model.TemplateSubject;
            template.TemplateRefNo        = model.TemplateRefNo;
            template.enableEmail          = model.enableEmail;
            template.enableSMSMessage     = model.enableSMSMessage;
            template.SMSMessage           = model.SMSMessage;
            template.enableWebMessage     = model.enableWebMessage;
            template.WebMessage           = model.WebMessage;
            template.WebNotifyLink        = model.WebNotifyLink;
            template.LastModified         = DateTime.Now;

            db.Entry(template).State = EntityState.Modified;
            db.Entry(template).Property(x => x.NotificationType).IsModified     = true;
            db.Entry(template).Property(x => x.NotificationCategory).IsModified = false;
            db.Entry(template).Property(x => x.TemplateName).IsModified         = true;
            db.Entry(template).Property(x => x.TemplateMessage).IsModified      = true;
            db.Entry(template).Property(x => x.TemplateSubject).IsModified      = true;
            db.Entry(template).Property(x => x.TemplateRefNo).IsModified        = true;
            db.Entry(template).Property(x => x.enableSMSMessage).IsModified     = true;
            db.Entry(template).Property(x => x.SMSMessage).IsModified           = true;
            db.Entry(template).Property(x => x.enableWebMessage).IsModified     = true;
            db.Entry(template).Property(x => x.WebMessage).IsModified           = true;
            db.Entry(template).Property(x => x.WebNotifyLink).IsModified        = true;
            db.Entry(template).Property(x => x.LastModified).IsModified         = true;
            db.Entry(template).Property(x => x.CreatedBy).IsModified            = false;

            //getAllParam first dan delete dulu
            var listParam = db.TemplateParameters.Where(p => p.NotificationType == model.NotificationType).ToList();

            db.TemplateParameters.RemoveRange(listParam);

            //lepas tu add yg baru
            foreach (var item in model.ParameterList)
            {
                TemplateParameters param = new TemplateParameters
                {
                    NotificationType      = model.NotificationType,
                    TemplateParameterType = item
                };
                db.TemplateParameters.Add(param);
            }

            db.Configuration.ValidateOnSaveEnabled = true;
            db.SaveChanges();

            return(Ok());
        }
        // GET: Template/EmailTemplates/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var response = await WepApiMethod.SendApiAsync <DetailsNotificationTemplateModel>(HttpVerbs.Get, $"Template/Email?id={id}");

            if (!response.isSuccess)
            {
                return(HttpNotFound());
            }

            EditNotificationTemplateModel model = new EditNotificationTemplateModel
            {
                Id = response.Data.Id,
                NotificationType     = response.Data.NotificationType,
                NotificationCategory = response.Data.NotificationCategory,
                TemplateName         = response.Data.TemplateName,
                TemplateSubject      = response.Data.TemplateSubject,
                TemplateRefNo        = response.Data.TemplateRefNo,
                TemplateMessage      = HttpUtility.HtmlDecode(response.Data.TemplateMessage),
                enableEmail          = response.Data.enableEmail,
                enableSMSMessage     = response.Data.enableSMSMessage,
                SMSMessage           = response.Data.SMSMessage,
                enableWebMessage     = response.Data.enableWebMessage,
                WebMessage           = response.Data.WebMessage,
                WebNotifyLink        = response.Data.WebNotifyLink
            };

            model.NotificationTypeList = (Enum.GetValues(typeof(NotificationType)).Cast <int>()
                                          .Select(e => new SelectListItem()
            {
                Text = ((DisplayAttribute)
                        typeof(NotificationType)
                        .GetMember(Enum.GetName(typeof(NotificationType), e).ToString())
                        .First()
                        .GetCustomAttributes(typeof(DisplayAttribute), false)[0]).Name,
                //Enum.GetName(typeof(NotificationType), e),
                Value = e.ToString()
            })).ToList();

            /*
             * foreach (TemplateParameterType param in Enum.GetValues(typeof(TemplateParameterType)))
             * {
             *  ParameterList paramList = new ParameterList
             *  {
             *      TemplateParameterType = param,
             *      parameterDisplayName = param.GetDisplayName()
             *  };
             *  model.TemplateParameterTypeList.Add(paramList);
             * }*/
            model.TemplateParameterTypeList = new List <ParameterList>();
            var response2 = await WepApiMethod.SendApiAsync <List <TemplateParameterType> >
                                (HttpVerbs.Get, $"Reminder/SLA/GetParameterList?id={(int)model.NotificationType}");

            if (response2.isSuccess && response2.Data != null)
            {
                foreach (var item in response2.Data)
                {
                    ParameterList paramList = new ParameterList
                    {
                        TemplateParameterType = item,
                        parameterDisplayName  = item.GetDisplayName()
                    };
                    model.TemplateParameterTypeList.Add(paramList);
                }
            }
            return(View(model));
        }