public int Add(TPOCurrentRawMaterialDto dto) { var entity = new TPOCurrentRawMaterial(); try { dto.DateEntered = DateTime.Now; dto.EnteredBy = CurrentUserName; dto.LastModified = DateTime.Now; dto.ModifiedBy = CurrentUserName; Mapper.Map(dto, entity); _repository.Repository <TPOCurrentRawMaterial>().Insert(entity); _repository.Save(); } catch (DbEntityValidationException valEx) { HandleValidationException(valEx); } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }
public JsonResult RawMaterialAjaxDelete(string id) { ResponseMessage responseMessage; try { TPOCurrentRawMaterial tpoCurrentRawMaterial = JsonConvert.DeserializeObject <TPOCurrentRawMaterial>(id); if (tpoCurrentRawMaterial != null) { TPOCurrentRawMaterialDto dto = new TPOCurrentRawMaterialDto(); using (TPOCurrentRawMaterialService service = new TPOCurrentRawMaterialService()) { Mapper.Map(tpoCurrentRawMaterial, dto); if (tpoCurrentRawMaterial.ID > 0) { service.Delete(dto.ID); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulDelete); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }
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; } }
public int AddTPOCurrentRawMaterial(TPOCurrentRawMaterialDto tpoCurrentRawMaterialDto) { var tpoCurrentRawMaterialEntity = new TPOCurrentRawMaterial(); try { tpoCurrentRawMaterialDto.ModifiedBy = CurrentUserName; tpoCurrentRawMaterialDto.EnteredBy = CurrentUserName; tpoCurrentRawMaterialDto.LastModified = DateTime.Now; tpoCurrentRawMaterialDto.DateEntered = DateTime.Now; Mapper.Map(tpoCurrentRawMaterialDto, tpoCurrentRawMaterialEntity); _repository.Repository <TPOCurrentRawMaterial>().Insert(tpoCurrentRawMaterialEntity); _repository.Save(); } catch (DbEntityValidationException valEx) { var sb = new StringBuilder(); foreach (var failure in valEx.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), valEx ); // Add the original exception as the innerException } catch (Exception ex) { LogException(ex); throw; } return(tpoCurrentRawMaterialEntity.ID); }
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); }