Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <CustomerTypeDto> CreateCustomerType(CustomerTypeDto customerTypeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (customerTypeDto == null)
                    {
                        return(null);
                    }
                    else
                    {
                        db.CustomerTypes.Add(customerTypeDto.ToModel());
                        await db.SaveChangesAsync();

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