Пример #1
0
        /// <summary>
        /// Update person details and skills
        /// </summary>
        /// <param name="entity">Person details to update</param>
        /// <returns>Rows effected</returns>
        public async Task <int> Update(People entity)
        {
            //First delete this person's skills from the table
            _logger.LogInformation("Deleting person skills");

            _dbContext.PersonSkills.RemoveRange(_dbContext.PersonSkills.Where(x => x.PersonId == entity.PersonId));
            _dbContext.SaveChanges();

            //Now update/add back person skills
            _logger.LogInformation("Updating person skills");

            foreach (var skill in entity.PersonSkills)
            {
                _dbContext.PersonSkills.Add(new PersonSkills {
                    PersonId = entity.PersonId, SkillId = skill.SkillId
                });
            }

            entity.PersonSkills = null;
            _dbContext.Set <People>().Update(entity);

            _logger.LogInformation("Updated person details");

            return(await _dbContext.SaveChangesAsync());
        }
Пример #2
0
        public Order CreateOrder(CreateOrderRequestDTO orderDto)
        {
            var order = OrderMap.Map(orderDto);

            this.ValidateOrder(order);

            order.OrderStatus = OrderStatus.Pending;

            _context.Add(order);
            _context.SaveChanges();

            return(order);
        }
 public int Save()
 {
     return(_context.SaveChanges());
 }