Пример #1
0
        public PurchaseDto[] CreateCollection(PurchaseDto[] dtoCol)
        {
            PurchaseEntity[] entityArray = new PurchaseEntity[dtoCol.Length];

            for (int i = 0; i < dtoCol.Length; i++)
            {
                var entity = new PurchaseEntity
                {
                    MadeById = userId,
                    MadeOn   = dtoCol[i].MadeOn,
                    Price    = dtoCol[i].Price,
                    ThingId  = dtoCol[i].ThingId,
                };

                context.Purchases.Add(entity);
                entityArray[i] = entity;
            }
            context.SaveChanges();

            PurchaseDto[] retDtoCol = new PurchaseDto[entityArray.Length];

            for (int i = 0; i < entityArray.Length; i++)
            {
                retDtoCol[i] = toDto(entityArray[i]);
            }

            return(retDtoCol);
        }
Пример #2
0
 private PurchaseDto toDto(PurchaseEntity entity)
 {
     return(new PurchaseDto
     {
         MadeById = entity.MadeById,
         Price = entity.Price,
         ThingId = entity.ThingId,
         MadeOn = entity.MadeOn,
         PurchaseId = entity.PurchaseId
     });
 }
Пример #3
0
        public PurchaseDto Create(PurchaseDto dto)
        {
            var entity = new PurchaseEntity()
            {
                ThingId  = dto.ThingId,
                MadeById = dto.MadeById,
                Price    = dto.Price,
                MadeOn   = dto.MadeOn,
            };

            context.Purchases.Add(entity);
            context.SaveChanges();

            dto.PurchaseId = entity.PurchaseId;

            throw new NotImplementedException();
        }