Beispiel #1
0
        public Tuple <bool, string> SaveEmailTemplate(string currentUserId, dynamic item)
        {
            bool   success = false;
            string msg = "";
            int    ProcessId, StepId;
            int?   TemplateId;
            string Subject, Body, UserId;
            bool   Enabled;

            try
            {
                //if (checkHavePermission(currentUserId, "ADMIN", "Email Template"))
                //{
                TemplateId = item.TemplateId;
                ProcessId  = item.ProcessId;
                StepId     = item.StepId;
                Subject    = item.Subject;
                Body       = item.Body;
                UserId     = item.UserId;
                Enabled    = item.Enabled;

                if (TemplateId.GetValueOrDefault(0) != 0)
                {
                    var template = Db.EmailTemplate.Where(p => p.EmailTemplateID == TemplateId).FirstOrDefault();
                    if (template != null)
                    {
                        var haveRecord = Db.EmailTemplate.Where(p => p.ProcessID == ProcessId && p.ActivityGroupID == StepId && p.EmailTemplateID != TemplateId).FirstOrDefault();
                        if (haveRecord == null)
                        {
                            template.ProcessID       = ProcessId;
                            template.ActivityGroupID = StepId;
                            template.Subject         = Subject;
                            template.Body            = Body;
                            template.CreatedOn       = DateTime.Now;
                            template.CreatedBy       = UserId;
                            template.Enabled         = Enabled;
                            Db.SaveChanges();
                            success = true;
                        }
                        else
                        {
                            success = false;
                            msg     = "This process and activity group already have email template.";
                        }
                    }
                    else
                    {
                        success = false;
                        msg     = "Email template not found.";
                    }
                }
                else
                {
                    var haveRecord = Db.EmailTemplate.Where(p => p.ProcessID == ProcessId && p.ActivityGroupID == StepId).FirstOrDefault();
                    if (haveRecord == null)
                    {
                        EmailTemplate template = new EmailTemplate();
                        template.ProcessID       = ProcessId;
                        template.ActivityGroupID = StepId;
                        template.Subject         = Subject;
                        template.Body            = Body;
                        template.CreatedOn       = DateTime.Now;
                        template.CreatedBy       = UserId;
                        template.Enabled         = Enabled;
                        Db.EmailTemplate.Add(template);
                        Db.SaveChanges();
                        success = true;
                    }
                    else
                    {
                        success = false;
                        msg     = "This process and activity group already have email template.";
                    }
                }
                //} else
                //{
                //    throw new UnauthorizedAccessException();
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Tuple.Create(success, msg));
        }