コード例 #1
0
        /// <summary>
        /// This method updates a customer and returns true if successful
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public async Task <bool> UpdateCustomer(CustomerDVM customer)
        {
            bool result = false;

            if (customer != null)
            {
                Customer c = await customerRepository.GetAsync(customer.Id);

                if (c != null)
                {
                    c.Firstname = customer.Firstname;
                    c.Email     = customer.Email;
                    c.Lastname  = customer.Lastname;
                    c.Phone     = customer.Phone;

                    try
                    {
                        await customerRepository.UpdateAsync(c);

                        result = true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// This method gets customer by id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <CustomerDVM> GetCustomerByID(int Id)
        {
            CustomerDVM cdvm = new CustomerDVM();

            if (Id > 0)
            {
                Customer c = await customerRepository.GetAsync(Id);

                if (c != null)
                {
                    cdvm = mapper.Map <CustomerDVM>(c);
                }
            }
            return(cdvm);
        }
コード例 #3
0
        /// <summary>
        /// This method Adds a new customer and returns the id
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public async Task <int> AddCustomer(CustomerDVM customer)
        {
            int id = 0;

            if (customer != null)
            {
                Customer c = mapper.Map <Customer>(customer);
                try
                {
                    var obj = await customerRepository.InsertAsync(c);

                    id = obj.Id;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(id);
        }