public void Add(CurrentRawMaterialDTO dto) { try { using (var context = new TPOMVCApplicationEntities()) { var newEntity = new TPOCurrentRawMaterial(); newEntity.RawMaterialReceivedID = dto.RawMaterialReceivedId; newEntity.LineID = dto.LineId; newEntity.PlantID = dto.PlantId; newEntity.DateEntered = dto.DateEntered; newEntity.EnteredBy = dto.EnteredBy; newEntity.ModifiedBy = dto.ModifiedBy; newEntity.LastModified = dto.LastModified; newEntity.Plant = context.Plants.Where(p => p.ID == dto.PlantId).FirstOrDefault(); newEntity.RawMaterialReceived = context.RawMaterialReceiveds.Where(m => m.ID == dto.RawMaterialReceivedId).FirstOrDefault(); context.TPOCurrentRawMaterials.Add(newEntity); context.SaveChanges(); } } catch (Exception ex) { throw; } }
private CurrentRawMaterialDTO MapCurrentRawMaterialViewModelToDTO(CurrentRawMaterialViewModel viewModel) { var dto = new CurrentRawMaterialDTO { Id = viewModel.Id, PlantId = viewModel.PlantId, LineId = viewModel.LineId, LotId = viewModel.LotId, RawMaterialReceivedId = viewModel.RawMaterialReceivedId, RawMaterialReceivedCode = viewModel.RawMaterialReceivedCode, LastModified = viewModel.LastModified, ModifiedBy = viewModel.ModifiedBy, DateEntered = viewModel.DateEntered, EnteredBy = viewModel.EnteredBy }; if (dto.PlantId == 0) { dto.PlantId = CurrentPlantId; } return(dto); }
private CurrentRawMaterialViewModel MapCurrentRawMaterialDTOToViewModel(CurrentRawMaterialDTO dto) { var vm = new CurrentRawMaterialViewModel { Id = dto.Id, LineId = dto.LineId, PlantId = dto.PlantId, RawMaterialReceivedId = dto.RawMaterialReceivedId, RawMaterialReceivedCode = dto.RawMaterialReceivedCode, LotId = dto.LotId, DateEntered = dto.DateEntered, EnteredBy = dto.EnteredBy, LastModified = dto.LastModified, ModifiedBy = dto.ModifiedBy }; if (vm.PlantId == 0) { vm.PlantId = CurrentPlantId; } return(vm); }
private static CurrentRawMaterialDTO MapToDTO(TPOCurrentRawMaterial dbo) { //TODO: Add mapper var dto = new CurrentRawMaterialDTO { Id = dbo.ID, PlantId = dbo.PlantID, RawMaterialReceivedId = dbo.RawMaterialReceivedID, RawMaterialReceivedCode = dbo.RawMaterialReceived.RawMaterial.Code, QuantityReceived = dbo.RawMaterialReceived.QuantityReceived, QuantityShipped = dbo.RawMaterialReceived.QuantityShipped, QuantityUsed = dbo.RawMaterialReceived.QuantityUsedThisLot, LotId = dbo.RawMaterialReceived.LotNumber, LineId = dbo.LineID, DateEntered = dbo.DateEntered, EnteredBy = dbo.EnteredBy, LastModified = dbo.LastModified, ModifiedBy = dbo.ModifiedBy }; return(dto); }
public void Update(CurrentRawMaterialDTO dto) { try { using (var context = new TPOMVCApplicationEntities()) { var toUpdate = context.TPOCurrentRawMaterials.Find(dto.Id); toUpdate.LineID = dto.LineId; toUpdate.PlantID = dto.PlantId; // do not allow edit to initial data //toUpdate.DateEntered = dto.DateEntered; //if (!string.IsNullOrWhiteSpace(dto.EnteredBy)) //{ // toUpdate.EnteredBy = dto.EnteredBy; //} if (!string.IsNullOrWhiteSpace(dto.ModifiedBy)) { toUpdate.ModifiedBy = dto.ModifiedBy; } toUpdate.LastModified = DateTime.Now; toUpdate.Plant = context.Plants.Where(p => p.ID == dto.PlantId).FirstOrDefault(); toUpdate.RawMaterialReceivedID = dto.RawMaterialReceivedId; toUpdate.RawMaterialReceived = context.RawMaterialReceiveds.Where(m => m.ID == dto.RawMaterialReceivedId).FirstOrDefault(); context.Entry(toUpdate).State = EntityState.Modified; context.SaveChanges(); } } catch (Exception ex) { throw; } }