Exemplo n.º 1
0
    public ActionResult Insert(Learning oldLearning, Learning newLearning, AssistantData[] newAssistants, int userId, int companyId)
    {
        var    res       = ActionResult.NoAction;
        string extradata = Learning.Differences(oldLearning, newLearning);

        if (!string.IsNullOrEmpty(extradata))
        {
            // Si se informa la fecha de finalización el estado pasa ser "realizado"
            if (newLearning.RealFinish.HasValue)
            {
                newLearning.Status = 1;
            }

            res = newLearning.Insert(userId);
            if (res.Success)
            {
                ActivityLog.Learning(newLearning.Id, userId, companyId, LearningLogActions.Create, extradata);
            }

            foreach (var assistant in newAssistants)
            {
                var newAssistant = new Assistant
                {
                    CompanyId = companyId,
                    Completed = null,
                    Success   = null,
                    Learning  = new Learning {
                        Id = newLearning.Id
                    },
                    Employee = new Employee(assistant.EmployeeId, true)
                };

                if (newAssistant.Employee.JobPosition != null)
                {
                    newAssistant.JobPosition = newAssistant.Employee.JobPosition;
                }

                newAssistant.Insert(userId);
            }

            res.SetSuccess(newLearning.Id);
        }

        return(res);
    }
Exemplo n.º 2
0
    public ActionResult Update(Learning oldLearning, Learning newLearning, int[] newAssistants, int userId, int companyId)
    {
        var    res       = ActionResult.NoAction;
        string extradata = Learning.Differences(oldLearning, newLearning);

        if (!string.IsNullOrEmpty(extradata))
        {
            res = newLearning.Update(userId);
            if (res.Success)
            {
                ActivityLog.Learning(newLearning.Id, userId, companyId, LearningLogActions.Modified, extradata);
                res.SetSuccess(newLearning.Id.ToString());
            }
        }

        foreach (int assistantId in newAssistants)
        {
            var newAssistant = new Assistant
            {
                CompanyId = companyId,
                Completed = null,
                Success   = null,
                Learning  = new Learning {
                    Id = newLearning.Id
                },
                Employee = new Employee(assistantId, true)
            };

            newAssistant.JobPosition = newAssistant.Employee.JobPosition;
            newAssistant.Insert(userId);
        }

        if (res.MessageError == ActionResult.NoAction.MessageError)
        {
            res.SetSuccess();
        }

        return(res);
    }