Ejemplo n.º 1
0
        /// <summary>
        /// Add / Update Customer record
        /// </summary>
        /// <param name="model">Dto.CustomerViewModel </param>
        /// <returns>bool</returns>
        public bool Save(Dto.CustomerViewModel model)
        {
            var customer = new Domain.DomainObjects.Customer();

            if (model.Id.Equals(default(Guid)))
            {
                customer        = AutoMapper.Mapper.Map <Dto.CustomerViewModel, Domain.DomainObjects.Customer>(model);
                customer.Id     = Guid.NewGuid();
                customer.Status = 1;

                _context.Customer.Add(customer);
            }
            else
            {
                customer = GetCustomer(model.Id);

                if (customer == null)
                {
                    return(false);
                }

                customer = AutoMapper.Mapper.Map <Dto.CustomerViewModel, Domain.DomainObjects.Customer>(model);
            }
            var result = _context.SaveChanges();

            return(result > 0 ? true : false);
        }
        /// <summary>
        /// Add / Update Customer record
        /// </summary>
        /// <param name="model">Dto.CustomerViewModel </param>
        /// <returns>bool</returns>
        public bool Save(Dto.CustomerViewModel model)
        {
            var customer = new Domain.DomainObjects.Customer();
            if (model.Id.Equals(default(Guid)))
            {
                customer = AutoMapper.Mapper.Map<Dto.CustomerViewModel, Domain.DomainObjects.Customer>(model);
                customer.Id = Guid.NewGuid();
                customer.Status = 1;

                _context.Customer.Add(customer);
            }
            else
            {
                customer = GetCustomer(model.Id);

                if (customer == null)
                    return false;

                customer = AutoMapper.Mapper.Map<Dto.CustomerViewModel, Domain.DomainObjects.Customer>(model);
            }
            var result = _context.SaveChanges();

            return result > 0 ? true : false;
        }