public PositionDTO(PositionDTO position) { PositionId = position.PositionId; PositionTitle = position.PositionTitle; Section = position.Section; Order = position.Order; }
public PositionEditWindow(PositionDTO position) { PEViewModel = new PositionEditViewModel{OriginalPosition = position}; InitializeComponent(); this.DataContext = PEViewModel.EditedPosition; }
public ListResponse<PositionDTO> GetAllPositions() { using (var context = new AF_Context()) { try { List<PositionDTO> tmp = new List<PositionDTO>(); foreach (Position pos in context.Positions.OrderBy(s => s.Section).ThenBy(o => o.Order)) { var newPositionDto = new PositionDTO() { PositionId = pos.PositionId, PositionTitle = pos.PositionTitle, Section = pos.Section, Order = pos.Order }; tmp.Add(newPositionDto); } return (new ListResponse<PositionDTO>(tmp)); } catch (Exception ex) { throw; } } }
public SingleItemResponse<PositionDTO> GetPosition(int id) { using (var context = new AF_Context()) { try { Position pos = context.Positions.First(p => p.PositionId == id); //awa.Editor = context.Users.First(u => u.UserId == awa.EditedBy); var newPositionDto = new PositionDTO() { PositionId = pos.PositionId, PositionTitle = pos.PositionTitle, Section = pos.Section, Order = pos.Order }; return (new SingleItemResponse<PositionDTO>(newPositionDto)); } catch (Exception ex) { throw; } } }
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; } } }