예제 #1
0
        public string AddAssignment(Assignment assignment)
        {
            string id          = "";
            var    _assignment = _assignmentRepository.GetByWorkOrder(assignment.WorkOrderId);

            if (_assignment == null)
            {
                id                      = Guid.NewGuid().ToString();
                assignment.Id           = id;
                assignment.CreationDate = DateTime.Now;
                assignment.StartDate    = assignment.EstimatedStartDate;
                _assignmentRepository.Add(assignment);
                assignment.Active = false;
            }
            else
            {
                id = _assignment.Id;
                assignment.Active = true;
            }

            assignment.AssignedPersonnel.ForEach(p => {
                p.AssignmentId = id;                 //assignment.Id;
            });
            if (!assignment.Active)
            {
                assignment.Location.AssignmentId = id;                 // assignment.Id;
                _assignmentRepository.AddLocation(assignment.Location);
            }
            _assignmentRepository.AddPersonnel(assignment.AssignedPersonnel);
            return(id);
            //return assignment.Id;
        }