Exemplo n.º 1
0
        ProcessNewAssignment(ANWI.Messaging.IMessagePayload p)
        {
            ANWI.Messaging.NewAssignment ns = p as ANWI.Messaging.NewAssignment;

            Datamodel.Assignment a = null;
            bool success           = Datamodel.Assignment.Create(
                ref a, ns.userId, ns.shipId, ns.roleId);

            if (success)
            {
                logger.Info($"Started assignment for user {ns.userId} role" +
                            $" {ns.roleId} on ship {ns.shipId}");
            }
            else
            {
                logger.Error("Failed to start assignment for user" +
                             $" {ns.userId} on ship {ns.shipId}");
            }

            if (ns.userId == GetUser().profile.id)
            {
                GetUser().RefreshProfile();
            }

            return(new ANWI.Messaging.ConfirmUpdate(p, success, ns.shipId));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets a user's current assignment
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public static Assignment FetchCurrentAssignment(int userId)
 {
     Datamodel.Assignment a = null;
     if (Datamodel.Assignment.FetchCurrentAssignment(ref a, userId))
     {
         return(new Assignment(a));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets an assignment by its ID
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Assignment FetchById(int id)
 {
     Datamodel.Assignment a = null;
     if (Datamodel.Assignment.FetchById(ref a, id))
     {
         return(new Assignment(a));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 4
0
        private Assignment(Datamodel.Assignment a)
        {
            id = a.id;

            _userId = a.user;

            _shipId = a.ship;
            Vessel ship = Vessel.FetchById(_shipId);

            if (ship == null)
            {
                throw new ArgumentException(
                          "Assignment does not have valid ship ID");
            }
            shipName       = ship.name;
            shipHullNumber = ship.fullHullNumber;

            _roleId = a.role;
            Datamodel.AssignmentRole role = null;
            if (!Datamodel.AssignmentRole.FetchById(ref role, _roleId))
            {
                throw new ArgumentException(
                          "Assignment does not have valid role ID");
            }
            roleName      = role.name;
            roleIsCompany = role.isCompany;

            startDate = DateTimeOffset.FromUnixTimeSeconds(a.from).DateTime;
            if (a.until != -1)
            {
                hasEndDate = true;
                endDate    = DateTimeOffset.FromUnixTimeSeconds(a.until).DateTime;
            }
            else
            {
                hasEndDate = false;
            }
        }