public async Task <LineDto> UpdateLine(LineDto line, string clientId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (line != null)
                    {
                        if (line.ClientId == clientId)
                        {
                            LineEntity entity = line.ToModel();
                            entity.LineId = line.LineId;
                            db.Lines.Attach(entity);
                            foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                            {
                                if (propName != "LineId")
                                {
                                    db.Entry(entity).Property(propName).IsModified = true;
                                }
                            }
                            await db.SaveChangesAsync();

                            return(entity.ToDto());
                        }
                        return(null);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
        public async Task <PackageDto> UpdatePackage(PackageDto package, int lineId, string clientId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (package != null)
                    {
                        if (CheckIfPackageBelongsToClient(package, lineId, clientId))
                        {
                            PackageEntity entity = package.ToModel();
                            entity.PackageId = package.PackageId;
                            db.Packages.Attach(entity);
                            foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                            {
                                if (propName != "PackageId")
                                {
                                    db.Entry(entity).Property(propName).IsModified = true;
                                }
                            }
                            await db.SaveChangesAsync();

                            return(entity.ToDto());
                        }
                        return(null);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #3
0
        public async Task <ClientDto> UpdateClient(ClientDto client, string clientId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (client != null && clientId != null)
                    {
                        client.ClientId = clientId;
                        ClientEntity entity = client.ToModel();
                        db.Clients.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != nameof(entity.ClientId))
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #4
0
        public async Task <CallsDto> UpdateCall(CallsDto call)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (call != null)
                    {
                        CallsEntity entity = call.ToModel();
                        entity.CallId = call.CallId;
                        db.Calls.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "CallId")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
        public async Task <SelectedNumbersDto> UpdateSelectedNumber(SelectedNumbersDto number)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (number != null)
                    {
                        SelectedNumbersEntity entity = number.ToModel();
                        entity.Id = number.Id;
                        db.SelectedNumbers.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "Id")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
        public async Task <PaymentDto> UpdatePayment(PaymentDto payment)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (payment != null)
                    {
                        PaymentEntity entity = payment.ToModel();
                        entity.PaymentId = payment.PaymentId;
                        db.Payment.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "PaymentId")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #7
0
        public async Task <SMSDto> UpdateSMS(SMSDto sms)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (sms != null)
                    {
                        SMSEntity entity = sms.ToModel();
                        entity.SMSId = sms.SMSId;
                        db.SMS.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "SMSId")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #8
0
        public async Task <LineDto> UpdateLine(int id, LineDto lineDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (lineDto != null && id != 0 && CheckIfLineNumberAlreadyExist(lineDto.Number))
                    {
                        lineDto.LineId = id;
                        Line entity = lineDto.ToModel();
                        db.Lines.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != nameof(entity.LineId))
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #9
0
        public IEnumerable <string> GetLineSelectedNumbers(int lineId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    List <string>   list   = new List <string>();
                    SelectedNumbers entity = db.SelectedNumbers.Where(s => s.Line.LineId == lineId).FirstOrDefault();
                    foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                    {
                        if (propName.EndsWith("Number"))
                        {
                            if (db.Entry(entity).Property(propName).CurrentValue != null)
                            {
                                list.Add(db.Entry(entity).Property(propName).CurrentValue.ToString());
                            }
                        }
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #10
0
        public async Task <PaymentDto> UpdatePayment(int id, PaymentDto paymentDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                if (id != paymentDto.CustomerId)
                {
                    return(null);
                }
                else
                {
                    var py = db.Payments.FirstOrDefault(p => p.PaymentId == id);
                    if (py == null)
                    {
                        return(null);
                    }
                    else
                    {
                        Payment payment = paymentDto.ToModel();
                        db.Entry(payment).State = System.Data.Entity.EntityState.Modified;
                        await db.SaveChangesAsync();

                        return(py.ToDto());
                    }
                }
            }
        }
Пример #11
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);
                }
            }
        }
        public async Task <SelectedNumberDto> UpdateSelectedNumber(int id, SelectedNumberDto selectedNumberDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                if (id != selectedNumberDto.SelectedNumberId)
                {
                    return(null);
                }
                else
                {
                    var sn = db.SelectedNumbers.FirstOrDefault(s => s.SelectedNumberId == id);
                    if (sn == null)
                    {
                        return(null);
                    }
                    else
                    {
                        SelectedNumbers selectedNumber = selectedNumberDto.ToModel();
                        db.Entry(selectedNumber).State = System.Data.Entity.EntityState.Modified;
                        await db.SaveChangesAsync();

                        return(sn.ToDto());
                    }
                }
            }
        }
Пример #13
0
        public async Task <PackageDto> UpdatePackage(int id, PackageDto packageDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (id != packageDto.PackageId)
                    {
                        return(null);
                    }
                    else
                    {
                        Package p = db.Packages.FirstOrDefault(c => c.PackageId == id);
                        if (p == null)
                        {
                            return(null);
                        }
                        else
                        {
                            p = packageDto.ToModel();
                            db.Entry(p).State = System.Data.Entity.EntityState.Modified;
                            await db.SaveChangesAsync();

                            return(p.ToDto());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Пример #14
0
        public async Task <SMSDto> UpdateSMS(int id, SMSDto smsDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                if (id != smsDto.SMSId)
                {
                    return(null);
                }
                else
                {
                    var sms = db.SMSs.FirstOrDefault(s => s.SMSId == id);
                    if (sms == null)
                    {
                        return(null);
                    }
                    else
                    {
                        SMS sMS = smsDto.ToModel();
                        db.Entry(sMS).State = System.Data.Entity.EntityState.Modified;
                        await db.SaveChangesAsync();

                        return(sms.ToDto());
                    }
                }
            }
        }
 public async Task <IEnumerable <string> > GetSelectedNumberByLine(int lineId)
 {
     using (CellularCompanyContext db = new CellularCompanyContext())
     {
         try
         {
             IEnumerable <string> selectedNumbers = new List <string>();
             SelectedNumbers      selectedNum     = db.SelectedNumbers.FirstOrDefault(s => s.Line.LineId == lineId);
             var prop = db.Entry(selectedNum).CurrentValues.PropertyNames.Where(p => p.EndsWith("Number"));
             return(prop);
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }
        public async Task <ClientDto> UpdateClientClientType(ClientDto client, int typeId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (client != null && typeId != 0)
                    {
                        ClientEntity clientEntity = db.Clients.FirstOrDefault(c => c.ClientId == client.ClientId);
                        clientEntity.ClientTypeId = typeId;
                        db.Entry(clientEntity).Property(nameof(clientEntity.ClientTypeId)).IsModified = true;
                        await db.SaveChangesAsync();

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