public TaskTemplateWrapper UpdateTaskTemplate(
            int id,
            int containerid,
            string title,
            string description,
            Guid responsibleid,
            int categoryid,
            bool isNotify,
            long offsetTicks,
            bool deadLineIsFixed
            )
        {
            if (containerid <= 0 || string.IsNullOrEmpty(title) || categoryid <= 0) throw new ArgumentException();

            var updatingItem = DaoFactory.GetTaskTemplateDao().GetByID(id);
            if (updatingItem == null) throw new ItemNotFoundException();

            var container = DaoFactory.GetTaskTemplateContainerDao().GetByID(containerid);
            if (container == null) throw new ItemNotFoundException();

            var item = new TaskTemplate
                {
                    CategoryID = categoryid,
                    ContainerID = containerid,
                    DeadLineIsFixed = deadLineIsFixed,
                    Description = description,
                    isNotify = isNotify,
                    ResponsibleID = responsibleid,
                    Title = title,
                    ID = id,
                    Offset = TimeSpan.FromTicks(offsetTicks)
                };

            item.ID = DaoFactory.GetTaskTemplateDao().SaveOrUpdate(item);

            return ToTaskTemplateWrapper(item);
        }
 protected TaskTemplateWrapper ToTaskTemplateWrapper(TaskTemplate taskTemplate)
 {
     return new TaskTemplateWrapper
         {
             Category = GetTaskCategoryByID(taskTemplate.CategoryID),
             ContainerID = taskTemplate.ContainerID,
             DeadLineIsFixed = taskTemplate.DeadLineIsFixed,
             Description = taskTemplate.Description,
             ID = taskTemplate.ID,
             isNotify = taskTemplate.isNotify,
             Title = taskTemplate.Title,
             OffsetTicks = taskTemplate.Offset.Ticks,
             Responsible = EmployeeWraper.Get(taskTemplate.ResponsibleID)
         };
 }
        public int SaveOrUpdate(TaskTemplate item)
        {
            using (var db = GetDb())
            {
                if (item.ID == 0 && db.ExecuteScalar<int>(Query("crm_task_template").SelectCount().Where(Exp.Eq("id", item.ID))) == 0)
                {

                    item.ID = db.ExecuteScalar<int>(
                                        Insert("crm_task_template")
                                       .InColumnValue("id", 0)
                                       .InColumnValue("title", item.Title)
                                       .InColumnValue("category_id", item.CategoryID)
                                       .InColumnValue("description", item.Description)
                                       .InColumnValue("responsible_id", item.ResponsibleID)
                                       .InColumnValue("is_notify", item.isNotify)
                                       .InColumnValue("offset", item.Offset.Ticks)
                                       .InColumnValue("deadLine_is_fixed", item.DeadLineIsFixed)
                                       .InColumnValue("container_id", item.ContainerID)
                                       .InColumnValue("create_on", DateTime.UtcNow)
                                       .InColumnValue("create_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                                       .InColumnValue("last_modifed_on", DateTime.UtcNow)
                                       .InColumnValue("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                                       .Identity(1, 0, true));

                }
                else
                {

                    db.ExecuteNonQuery(
                        Update("crm_task_template")
                           .Set("title", item.Title)
                           .Set("category_id", item.CategoryID)
                           .Set("description", item.Description)
                           .Set("responsible_id", item.ResponsibleID)
                           .Set("is_notify", item.isNotify)
                           .Set("offset", item.Offset.Ticks)
                           .Set("deadLine_is_fixed", item.DeadLineIsFixed)
                           .Set("container_id", item.ContainerID)
                           .Set("last_modifed_on", DateTime.UtcNow)
                           .Set("last_modifed_by", ASC.Core.SecurityContext.CurrentAccount.ID)
                           .Where("id", item.ID));

                }

                return item.ID;
            }
        }