예제 #1
0
        public async Task <CustomerTypeDto> UpdateCustomerType(int id, CustomerTypeDto customerTypeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (id != customerTypeDto.CustomerTypeId)
                    {
                        return(null);
                    }
                    else
                    {
                        CustomerType ct = db.CustomerTypes.FirstOrDefault(c => c.CustomerTypeId == id);
                        if (ct == null)
                        {
                            return(null);
                        }
                        else
                        {
                            ct = customerTypeDto.ToModel();
                            db.Entry(ct).State = System.Data.Entity.EntityState.Modified;
                            await db.SaveChangesAsync();

                            return(ct.ToDto());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
예제 #2
0
        public async Task <CustomerTypeDto> DeleteCustomerType(int id)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    CustomerType customerType = await db.CustomerTypes.FindAsync(id);

                    if (customerType == null)
                    {
                        return(null);
                    }
                    else
                    {
                        db.CustomerTypes.Remove(customerType);
                        await db.SaveChangesAsync();

                        return(customerType.ToDto());
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
예제 #3
0
        public async Task <CustomerTypeDto> GetCustomerType(int id)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    CustomerType customerType = await db.CustomerTypes.FindAsync(id);

                    return(customerType.ToDto());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }