Exemplo n.º 1
0
        public async Task <Tbl_Customer> AddCustomerAsync(Tbl_Customer tbl_Customer)
        {
            await _context.Tbl_Customer.AddAsync(tbl_Customer);

            await _context.SaveChangesAsync();

            return(tbl_Customer);
        }
Exemplo n.º 2
0
 public bool RemoveCustomer(Tbl_Customer customer)
 {
     if (_context.Tbl_Customer.Any(x => x.Customer_ID == customer.Customer_ID))
     {
         _context.Tbl_Customer.Remove(_context.Tbl_Customer.Where(x => x.Customer_ID == customer.Customer_ID).FirstOrDefault());
         _context.SaveChanges();
     }
     return(true);
 }
Exemplo n.º 3
0
 public async Task <Tbl_Customer> UpdateCustomerAsync(int id, Tbl_Customer tbl_Customer)
 {
     _context.Update(tbl_Customer);
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         throw;
     }
     return(tbl_Customer);
 }
Exemplo n.º 4
0
 public bool EditCustomer(Tbl_Customer customer, int customer_id, int active_id, int field_id)
 {
     try
     {
         if (_context.Tbl_Customer.Any(x => x.Customer_ID == customer_id))
         {
             // user already exists
             Tbl_Customer ToBeUpdatedCustomer = _context.Tbl_Customer.First(x => x.Customer_ID == customer_id);
             ToBeUpdatedCustomer.Address = customer.Address;
             ToBeUpdatedCustomer.CompanyRegistrationName = customer.CompanyRegistrationName;
             ToBeUpdatedCustomer.CustomerConnector       = customer.CustomerConnector;
             ToBeUpdatedCustomer.CustomerName            = customer.CustomerName;
             ToBeUpdatedCustomer.EconomicalNumber        = customer.EconomicalNumber;
             ToBeUpdatedCustomer.Active             = customer.Active;
             ToBeUpdatedCustomer.CustomerField_ID   = customer.CustomerField_ID;
             ToBeUpdatedCustomer.Email              = customer.Email;
             ToBeUpdatedCustomer.FaxNo              = customer.FaxNo;
             ToBeUpdatedCustomer.MobileNo           = customer.MobileNo;
             ToBeUpdatedCustomer.NationalID         = customer.NationalID;
             ToBeUpdatedCustomer.PostalCode         = customer.PostalCode;
             ToBeUpdatedCustomer.RegistrationNumber = customer.RegistrationNumber;
             //ToBeUpdatedCustomer.SubscriptionCode = customer.SubscriptionCode;
             ToBeUpdatedCustomer.TelNo             = customer.TelNo;
             ToBeUpdatedCustomer.LastUpdateDate    = customer.LastUpdateDate;
             ToBeUpdatedCustomer.LastUpdateTime    = customer.LastUpdateTime;
             ToBeUpdatedCustomer.LastUpdateUser_ID = customer.LastUpdateUser_ID;
             if (_context.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 5
0
 public static Customer MapFrom(this Tbl_Customer customer)
 {
     return(new Customer
     {
         Id = customer.Id,
         Name = customer.Name,
         PhoneNumber = customer.PhoneNumber,
         Email = customer.Email,
         CurrencyId = customer.CurrencyId,
         TaxNumber = customer.TaxNumber,
         Address = customer.Address,
         IsEnabled = customer.IsEnabled,
         Refrence = customer.Refrence,
         Created_At = customer.Created_At,
         Updated_At = customer.Updated_At,
         BranchId = customer.BranchId,
         Website = customer.Website,
         CanLogin = customer.CanLogin,
         AccountNumber = customer.AccountNumber,
         SadadNumber = customer.SadadNumber
     });
 }
Exemplo n.º 6
0
        public int AddNewCustomer(Tbl_Customer customer, int customer_id, int active_id, int field_id)
        {
            try
            {
                Random generator = new Random();
                int    r         = generator.Next(100000, 1000000);

                Tbl_Customer ToBeInsertedCustomer = new Tbl_Customer();
                ToBeInsertedCustomer.Address = customer.Address;
                ToBeInsertedCustomer.CompanyRegistrationName = customer.CompanyRegistrationName;
                ToBeInsertedCustomer.CustomerConnector       = customer.CustomerConnector;
                ToBeInsertedCustomer.CustomerName            = customer.CustomerName;
                ToBeInsertedCustomer.EconomicalNumber        = customer.EconomicalNumber;
                ToBeInsertedCustomer.Active             = customer.Active;
                ToBeInsertedCustomer.CustomerField_ID   = customer.CustomerField_ID;
                ToBeInsertedCustomer.Email              = customer.Email;
                ToBeInsertedCustomer.FaxNo              = customer.FaxNo;
                ToBeInsertedCustomer.MobileNo           = customer.MobileNo;
                ToBeInsertedCustomer.NationalID         = customer.NationalID;
                ToBeInsertedCustomer.PostalCode         = customer.PostalCode;
                ToBeInsertedCustomer.RegistrationNumber = customer.RegistrationNumber;
                ToBeInsertedCustomer.SubscriptionCode   = r.ToString();
                ToBeInsertedCustomer.TelNo              = customer.TelNo;
                ToBeInsertedCustomer.LastUpdateDate     = customer.LastUpdateDate;
                ToBeInsertedCustomer.LastUpdateTime     = customer.LastUpdateTime;
                ToBeInsertedCustomer.LastUpdateUser_ID  = customer.LastUpdateUser_ID;

                _context.Tbl_Customer.Add(ToBeInsertedCustomer);
                _context.SaveChanges();

                return(ToBeInsertedCustomer.Customer_ID);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult <Tbl_Customer> > CreateCustomer(Tbl_Customer tbl_Customer)
        {
            var result = await _customerService.AddCustomerAsync(tbl_Customer);

            return(CreatedAtAction("GetCustomer", new { id = result.id }, result));
        }
Exemplo n.º 8
0
        public ActionResult InsertCustomer(CustomerModel model, string returnurl)
        {
            HttpSessionStateBase session = HttpContext.Session;

            try
            {
                if (model.Customer_ID == 0)
                {
                    // update process
                    Tbl_Customer tg = new Tbl_Customer();
                    tg.Address = model.Address;
                    tg.CompanyRegistrationName = model.CompanyRegistrationName;
                    tg.CustomerConnector       = model.CustomerConnector;
                    tg.CustomerField_ID        = model.CustomerField_ID;
                    tg.CustomerName            = model.CustomerName;
                    tg.EconomicalNumber        = model.EconomicalNumber;
                    tg.Email              = model.Email;
                    tg.FaxNo              = model.FaxNo;
                    tg.MobileNo           = model.MobileNo;
                    tg.NationalID         = model.NationalID;
                    tg.PostalCode         = model.PostalCode;
                    tg.RegistrationNumber = model.RegistrationNumber;
                    tg.SubscriptionCode   = model.SubscriptionCode;
                    tg.TelNo              = model.TelNo;
                    tg.Active             = model.IsActive_ID;
                    tg.LastUpdateUser_ID  = Convert.ToInt32(session["UserID"]);
                    tg.LastUpdateDate     = DateTime.Now.ToString("yyyy-MM-dd");
                    tg.LastUpdateTime     = DateTime.Now.ToString("HH:mm");
                    int res = _customerService.AddNewCustomer(tg, model.Customer_ID, model.IsActive_ID, model.CustomerField_ID);
                    if (res > 0)
                    {
                        var gridModel = new DataSourceResult
                        {
                            ExtraData = new CustomerListModel
                            {
                                Message          = Message.OperationSuccessful,
                                Customer_ID      = res,
                                SubscriptionCode = _customerService.GetCustomerById(res).SubscriptionCode,
                                MessageColor     = "green",
                            },
                            Total = 1
                        };
                        return(Json(gridModel));
                    }
                    else
                    {
                        var gridModel = new DataSourceResult
                        {
                            ExtraData = new CustomerListModel
                            {
                                Message      = Message.OperationUnsuccessful,
                                MessageColor = "red",
                            },
                            Total = 1
                        };
                        return(Json(gridModel));
                    }
                }
                else
                {
                    var gridModel = new DataSourceResult
                    {
                        ExtraData = new CustomerListModel
                        {
                            Message      = Message.OperationUnsuccessful,
                            MessageColor = "red",
                        },
                        Total = 1
                    };
                    return(Json(gridModel));
                }
            }
            catch (Exception ex)
            {
                var gridModel = new DataSourceResult
                {
                    ExtraData = new CustomerListModel
                    {
                        Message      = Message.OperationUnsuccessful,
                        MessageColor = "red",
                    },
                    Total = 1
                };
                return(Json(gridModel));
            }
        }