/// <summary> /// Finds the activity task status by name or create. /// </summary> /// <param name="context">The context.</param> /// <param name="name">The name.</param> /// <param name="nameEn">The name en.</param> /// <returns>ActivityTaskStatus.</returns> private static ActivityTaskStatus FindActivityTaskStatusByNameOrCreate( this ApplicationDbContext context, string alias, string name, string nameEn) { var result = context.ActivityTaskStatuses.FirstOrDefault(it => it.Alias == alias); if (result == null) { result = new ActivityTaskStatus() { Alias = alias, Name = name }; context.ActivityTaskStatuses.Add(result); context.SaveChanges(); } else { result.Name = name; context.SaveChanges(); } return(result); }
/// <summary> /// Finds the activity task by subject or create. /// </summary> /// <param name="context">The context.</param> /// <param name="subject">The subject.</param> /// <param name="status">The status.</param> /// <param name="userCreatedBy">The user created by.</param> /// <param name="userAssignTo">The user assign to.</param> /// <param name="isImportant">if set to <c>true</c> [is important].</param> /// <param name="dateDeadline">The date deadline.</param> /// <param name="dateEnd">The date end.</param> /// <param name="dateCreated">The date created.</param> /// <param name="goal">The goal.</param> /// <param name="company">The company.</param> /// <param name="successFactor">The success factor.</param> /// <param name="description">The description.</param> /// <returns>ActivityTask.</returns> private static ActivityTask FindActivityTaskBySubjectOrCreate( this ApplicationDbContext context, string subject, ActivityTaskStatus status, ApplicationUser userCreatedBy, ApplicationUser userAssignTo, bool isImportant, DateTime dateDeadline, DateTime dateEnd, DateTime dateCreated, Goal goal, Company company, string successFactor, string description) { var task1 = context.ActivityTasks.FirstOrDefault(it => it.Subject == subject); if (task1 == null) { task1 = new ActivityTask() { AssignTo = userAssignTo, CreatedBy = userCreatedBy, Subject = subject, DateCreated = dateCreated, DateDeadline = dateDeadline, DateEnd = dateEnd, Description = description, IsImportant = isImportant, Status = status, SuccessFactor = successFactor, Company = company, Goal = goal }; context.ActivityTasks.Add(task1); context.SaveChanges(); } return(task1); }