示例#1
0
        public static TimesheetViewModel CreateTimesheetViewModelFromTimesheet(Timesheet timeSheet)
        {
            TimesheetViewModel timeSheetViewModel = new TimesheetViewModel();
            timeSheetViewModel.TimesheetId = timeSheet.TimesheetId;
            timeSheetViewModel.EmployeeName = timeSheet.EmployeeName;
            timeSheetViewModel.PONumber = timeSheet.PONumber;
            timeSheetViewModel.ObjectState = ObjectState.Unchanged;
            timeSheetViewModel.RowVersion = timeSheet.RowVersion;

            foreach (TimesheetItem timeSheetItem in timeSheet.TimesheetItems)
            {
                TimesheetItemViewModel timeSheetItemViewModel = new TimesheetItemViewModel();
                timeSheetItemViewModel.TimesheetItemId = timeSheetItem.TimesheetItemId;
                timeSheetItemViewModel.ProductCode = timeSheetItem.ProductCode;
                timeSheetItemViewModel.Quantity = timeSheetItem.Quantity;
                timeSheetItemViewModel.UnitPrice = timeSheetItem.UnitPrice;

                timeSheetItemViewModel.ObjectState = ObjectState.Unchanged;
                timeSheetItemViewModel.RowVersion = timeSheetItem.RowVersion;

                timeSheetItemViewModel.TimesheetId = timeSheet.TimesheetId;

                timeSheetViewModel.TimesheetItems.Add(timeSheetItemViewModel);
            }

            return timeSheetViewModel;
        }
示例#2
0
        public static Timesheet CreateTimesheetFromTimesheetViewModel(TimesheetViewModel timeSheetViewModel)
        {
            Timesheet timeSheet = new Timesheet();
            timeSheet.TimesheetId = timeSheetViewModel.TimesheetId;
            timeSheet.EmployeeName = timeSheetViewModel.EmployeeName;
            timeSheet.PONumber = timeSheetViewModel.PONumber;
            timeSheet.ObjectState = timeSheetViewModel.ObjectState;
            timeSheet.RowVersion = timeSheetViewModel.RowVersion;

            int temporaryTimesheetItemId = -1;

            foreach (TimesheetItemViewModel timeSheetItemViewModel in timeSheetViewModel.TimesheetItems)
            {
                TimesheetItem timeSheetItem = new TimesheetItem();
                timeSheetItem.ProductCode = timeSheetItemViewModel.ProductCode;
                timeSheetItem.Quantity = timeSheetItemViewModel.Quantity;
                timeSheetItem.UnitPrice = timeSheetItemViewModel.UnitPrice;

                timeSheetItem.ObjectState = timeSheetItemViewModel.ObjectState;
                timeSheetItem.RowVersion = timeSheetItemViewModel.RowVersion;

                if (timeSheetItemViewModel.ObjectState != ObjectState.Added)
                    timeSheetItem.TimesheetItemId = timeSheetItemViewModel.TimesheetItemId;
                else
                {
                    timeSheetItem.TimesheetItemId = temporaryTimesheetItemId;
                    temporaryTimesheetItemId--;
                }

                timeSheetItem.TimesheetId = timeSheetViewModel.TimesheetId;

                timeSheet.TimesheetItems.Add(timeSheetItem);
            }

            return timeSheet;
        }