示例#1
0
        public object UpdateWorkFlowWithActions(int id, [FromBody] WorkFlowWithActionVM model)
        {
            object result = null; string message = ""; string errorcode = ""; string excp = "";

            if (model == null)
            {
                return(BadRequest());
            }
            using (_context)
            {
                using (var _ctxTransaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        var entityUpdate = _context.WorkFlow.FirstOrDefault(x => x.Id == model.WorkFlow.Id);

                        if (entityUpdate != null)
                        {
                            entityUpdate.Name        = model.WorkFlow.Name;
                            entityUpdate.Description = model.WorkFlow.Description;
                            entityUpdate.FormName    = model.WorkFlow.FormName;
                            entityUpdate.Status      = model.WorkFlow.Status;
                            entityUpdate.TriggerName = model.WorkFlow.TriggerName;

                            _context.SaveChanges();
                        }

                        if (model.WorkFlowActions.Count > 0)
                        {
                            //List<WorkFlowAction> listToRemove = _context.WorkFlowAction.Where(y => y.WorkFlowId == model.WorkFlow.Id).ToList();
                            //if(listToRemove.Count > 0)
                            //{
                            //    foreach (var Action in listToRemove)
                            //    {
                            //        _context.WorkFlowAction.Remove(Action);
                            //    }
                            //    _context.SaveChanges();
                            //}
                            foreach (var WFAction in model.WorkFlowActions)
                            {
                                if (WFAction.Id == 0)
                                {
                                    if (model.WorkFlow.Id != 0)
                                    {
                                        WFAction.WorkFlowId = model.WorkFlow.Id;
                                        _context.WorkFlowAction.Add(WFAction);
                                        _context.SaveChanges();
                                    }
                                }
                                else
                                {
                                    var entityUpdateAction = _context.WorkFlowAction.FirstOrDefault(x => x.Id == WFAction.Id);

                                    if (entityUpdateAction != null)
                                    {
                                        entityUpdateAction.Action      = WFAction.Action;
                                        entityUpdateAction.ActionOrder = WFAction.ActionOrder;
                                        entityUpdateAction.TemplateId  = WFAction.TemplateId;
                                        entityUpdateAction.MailAlertId = WFAction.MailAlertId;
                                        entityUpdateAction.TaskId      = WFAction.TaskId;
                                        entityUpdateAction.CheckListId = WFAction.CheckListId;
                                        entityUpdateAction.Name        = WFAction.Name;

                                        _context.SaveChanges();
                                    }
                                }
                            }
                        }

                        _ctxTransaction.Commit();
                        message   = "Entry Updated";
                        errorcode = "0";
                    }
                    catch (Exception e)
                    {
                        _ctxTransaction.Rollback(); e.ToString();
                        message   = "Entry Update Failed!!";
                        errorcode = "1";
                        excp      = e.ToString();
                    }

                    result = new
                    {
                        error = errorcode,
                        msg   = message,
                        excp  = excp
                    };
                }
            }
            return(result);
        }
示例#2
0
        public object CreateWorkFlowWithActions([FromBody] WorkFlowWithActionVM model)
        {
            object result    = null;
            string message   = "";
            string errorcode = "";
            string excp      = "";

            if (model == null)
            {
                return(BadRequest());
            }
            using (_context)
            {
                using (var _ctxTransaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        //WorkFlow objWorkFlow = new WorkFlow();
                        //objWorkFlow.Name = model.WorkFlow.Name;
                        //objWorkFlow.Description = model.WorkFlow.Description;
                        //objWorkFlow.FormName = model.WorkFlow.FormName;
                        //objWorkFlow.Status = model.WorkFlow.Status;
                        //objWorkFlow.TriggerName = model.WorkFlow.TriggerName;
                        //_context.WorkFlow.Add(objWorkFlow);
                        //await _ctx.SaveChangesAsync();
                        _context.WorkFlow.Add(model.WorkFlow);
                        _context.SaveChanges();
                        //_ctxTransaction.Commit();

                        if (model.WorkFlowActions.Count > 0)
                        {
                            foreach (var Action in model.WorkFlowActions)
                            {
                                if (model.WorkFlow.Id != 0)
                                {
                                    Action.WorkFlowId = model.WorkFlow.Id;
                                    _context.WorkFlowAction.Add(Action);
                                    _context.SaveChanges();
                                }
                            }
                        }
                        _ctxTransaction.Commit();
                        message   = "Saved Successfully";
                        errorcode = "0";
                    }
                    catch (Exception e)
                    {
                        _ctxTransaction.Rollback();
                        e.ToString();
                        message   = "Saved Error";
                        errorcode = "1";
                        excp      = e.ToString();
                    }

                    result = new
                    {
                        error = errorcode,
                        msg   = message,
                        excp  = excp
                    };
                }
            }
            return(result);
        }