示例#1
0
        public void Create(CreateTaskModel model)
        {
            var affectedSectors = new List <TaskSector>();


            var task = new Task
            {
                Title       = model.Title,
                DueDate     = DateTime.ParseExact(model.DueDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                Description = model.Description,

                IsReported = false
            };

            foreach (Sector value in Enum.GetValues(typeof(Sector)))
            {
                var property = model
                               .GetType()
                               .GetProperties()
                               .FirstOrDefault(p => p.Name.ToLower()
                                               .Equals(value.ToString().ToLower()));

                if (property.GetValue(model) != null)
                {
                    var taskSector = new TaskSector
                    {
                        Task   = task,
                        Sector = value
                    };
                    affectedSectors.Add(taskSector);
                }
            }

            var participants = new List <TaskParticipant>();

            foreach (var name in model.Participants.Split(new[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries))
            {
                var participant = new TaskParticipant
                {
                    Name = name.Trim(),
                    Task = task
                };

                participants.Add(participant);
            }

            task.Participants    = participants;
            task.AffectedSectors = affectedSectors;
            task.Level           = affectedSectors.Count();
            this.context.Tasks.Add(task);
            this.context.SaveChanges();
            //this.context.TaskParticipants.AddRange(participants);
            //this.context.SaveChanges();
            //this.context.TaskSectors.AddRange(affectedSectors);
        }
示例#2
0
        public TaskParticipant Delete(string id)
        {
            TaskParticipant user = _context.TaskParticipants.FirstOrDefault(x => x.TaskParticipantId.ToString() == id);

            if (user != null)
            {
                _context.TaskParticipants.Remove(user);
                _context.SaveChanges();
            }
            return(user);
        }
示例#3
0
 public void Add(TaskParticipant item)
 {
     if (item.TaskParticipantId.Equals(default(Guid)))
     {
         _context.TaskParticipants.Add(item);
     }
     else
     {
         TaskParticipant dbEntry = _context.TaskParticipants.FirstOrDefault(x => x.TaskParticipantId.Equals(item.TaskParticipantId));
         if (dbEntry != null)
         {
             dbEntry.UserTask      = item.UserTask;
             dbEntry.ParticipantId = item.ParticipantId;
             dbEntry.TaskId        = item.TaskId;
             dbEntry.User          = item.User;
         }
     }
 }
示例#4
0
 public void Edit(TaskParticipant item)
 {
     Edit(item);
 }