public Position(Position position)
 {
     PositionId = position.PositionId;
     PositionTitle = position.PositionTitle;
     Section = position.Section;
     Order = position.Order;
     EditDate = position.EditDate;
     EditedBy = position.EditedBy;
 }
 public Position UpdatePosition(Position updateData)
 {
     throw new NotImplementedException();
 }
        public SingleItemResponse<PositionDTO> UpdatePosition(PositionDTO updateData)
        {
            var updateDataFull = new Position()
            {
                PositionId = updateData.PositionId,
                PositionTitle = updateData.PositionTitle,
                Section = updateData.Section,
                Order = updateData.Order,
                EditedBy = GetUserId(),
                EditDate = DateTime.Now
            };

            using (var context = new AF_Context())
            {
                try
                {
                    Position pos = context.Positions.First(p => p.PositionId == updateData.PositionId);
                    context.Entry(pos).CurrentValues.SetValues(updateDataFull);
                    context.SaveChanges();
                    int id = updateData.PositionId;
                    return GetPosition(id);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
        public SingleItemResponse<PositionDTO> AddPosition(PositionDTO newPosition)
        {
            var newPositionFull = new Position()
            {
                PositionTitle = newPosition.PositionTitle,
                Section = newPosition.Section,
                Order = newPosition.Order,
                EditedBy = GetUserId(),
                EditDate = DateTime.Now
            };

            using (var context = new AF_Context())
            {
                try
                {
                    context.Positions.Add(newPositionFull);
                    context.SaveChanges();
                    int id = newPositionFull.PositionId;
                    return GetPosition(id);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
 public PositionEditWindow(Position position)
  {
      InitializeComponent();
      PEViewModel = new PositionEditViewModel(position);
      this.DataContext = PEViewModel.EditedPosition;
  }
 public async Task UpdatePosition(Position updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Position pos = context.Positions.First(p => p.PositionId == updateData.PositionId);
             context.Entry(pos).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddPosition(Position newPosition)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Positions.Add(newPosition);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
        // private constructor called by the async method

        public PositionEditViewModel(Position originalPosition)
        {
            OriginalPosition = originalPosition;
            EditedPosition = new Position(OriginalPosition);
        }
 public async Task UpdatePosition(Position updateData)
 {
     await DataAccess.UpdatePosition(updateData);
 }
 public async Task AddPosition(string title, int section, int order, int userId)
 {
     var newPosition= new Position
     {
         PositionTitle = title,
         Section = section,
         Order = order,
         EditDate = DateTime.Now,
         EditedBy = userId
     };
     await DataAccess.AddPosition(newPosition);
 }