Example #1
0
        public async Task <ActionResult <CustomerProfileDTO> > Put([FromBody] CustomerProfileDTO model)
        {
            //return a generic HTTP status 500 (server error)
            //if the client payload is invalid
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }



            return(await _customerProfileRepository.UpdateProfile(model));
        }
        public async Task <CustomerProfileDTO> GetCustomerProfile(CustomerInquiryFilterDTO customerInquiry)
        {
            try
            {
                CustomerProfileDTO customerProfileDTO = null;

                var customerInquiryFilter = new CustomerInquiryFilter
                {
                    CustomerId = customerInquiry.CustomerId,
                    Email      = customerInquiry.Email
                };

                var customerProfile = await _customerRepository.GetCustomersAsync(customerInquiryFilter);

                if (customerProfile == null)
                {
                    return(customerProfileDTO);
                }

                customerProfileDTO = new CustomerProfileDTO
                {
                    CustomerId         = customerProfile.CustomerId,
                    Name               = customerProfile.Name,
                    Email              = customerProfile.Email,
                    MobileNumber       = customerProfile.Email,
                    RecentTransactions = customerProfile.RecentTransactions.Select(x => new TransactionDTO
                    {
                        TransactionId     = x.TransactionId,
                        Amount            = x.Amount,
                        Date              = x.TransactionDateTime,
                        CurrencyCode      = x.CurrencyCode.ToString(),
                        TransactionStatus = x.Status.ToString()
                    }).ToList()
                };

                return(customerProfileDTO);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Create Customer/Company Profiler when Initial Time
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public CustomerProfileDTO CreateCustomerProfile(CustomerProfile model, string UserID)
        {
            TFPMEntities context  = new TFPMEntities();
            var          CProfile = context.CustomerProfiles.Where(o => o.CustomerName.Equals(model.CustomerName))
                                    .Select(x => new CustomerProfileDTO
            {
                CompanyID         = x.CompanyID,
                CustomerName      = x.CustomerName,
                City              = x.City,
                State             = x.State,
                AccountNumber     = x.AccountNumber,
                AccountOwnerEmail = x.AccountOwnerEmail,
                AccountOwnerName  = x.AccountOwnerName,
                AddressLine1      = x.AddressLine1,
                AddressLine2      = x.AddressLine2,
                ZipCode           = x.ZipCode,
                CompanyLogo       = x.CompanyLogo,
                CreatedOn         = x.CreatedOn,
                DotCount          = x.CustomerDOTNumbers.Count(a => a.IsDelete == false),
                UserCount         = x.AspNetUsers.Count(a => a.IsActive == true),
                ModifiedOn        = x.ModifiedOn,
                isActive          = x.isActive,
                CreatedBy         = x.CreatedBy,
                ModifiedBy        = x.ModifiedBy
            }).FirstOrDefault();;

            if (CProfile == null)
            {
                var customer = new CustomerProfile
                {
                    CustomerName      = model.CustomerName.Trim(),
                    CompanyLogo       = CommonFunctions.Trimstring(model.CompanyLogo),
                    AccountOwnerEmail = CommonFunctions.Trimstring(model.AccountOwnerEmail),
                    AccountOwnerName  = CommonFunctions.Trimstring(model.AccountOwnerName),
                    AddressLine1      = CommonFunctions.Trimstring(model.AddressLine1),
                    AddressLine2      = CommonFunctions.Trimstring(model.AddressLine2),
                    City      = CommonFunctions.Trimstring(model.City),
                    State     = CommonFunctions.Trimstring(model.State),
                    ZipCode   = CommonFunctions.Trimstring(model.ZipCode),
                    CreatedBy = UserID,
                    CreatedOn = DateTime.Now,
                    isActive  = true,
                    IsDelete  = false
                };
                context.CustomerProfiles.Add(customer);
                context.SaveChanges();
                customer.AccountNumber = model.CustomerName.Trim()[0].ToString().ToLower() + customer.CompanyID.ToString();//Account NUmber Generate logic
                context.SaveChanges();
                LocationConfig loc = new TF_BusinessLayer.LocationConfig();
                loc.CreateLocationChild(customer.CompanyID, UserID);
                var CustomerDTO = new CustomerProfileDTO
                {
                    CompanyID         = customer.CompanyID,
                    CustomerName      = customer.CustomerName,
                    City              = customer.City,
                    State             = customer.State,
                    AccountNumber     = customer.AccountNumber,
                    AccountOwnerEmail = customer.AccountOwnerEmail,
                    AccountOwnerName  = customer.AccountOwnerName,
                    AddressLine1      = customer.AddressLine1,
                    AddressLine2      = customer.AddressLine2,
                    ZipCode           = customer.ZipCode,
                    CompanyLogo       = customer.CompanyLogo,
                    CreatedOn         = customer.CreatedOn,
                    DotCount          = customer.CustomerDOTNumbers.Count(a => a.IsDelete == false),
                    UserCount         = customer.AspNetUsers.Count(a => a.IsActive == true),
                    ModifiedOn        = customer.ModifiedOn,
                    isActive          = customer.isActive,
                    CreatedBy         = customer.CreatedBy,
                    ModifiedBy        = customer.ModifiedBy
                };
                return(CustomerDTO);
            }
            else
            {
                return(CProfile);
            }
        }
        /// <summary>
        /// Update Customer Profile
        /// </summary>
        /// <param name="model"></param>
        /// <param name="RoleNames"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public CustomerProfileDTO UpdateCustomerProfile(CustomerProfile model, string RoleNames, string UserID)
        {
            TFPMEntities context  = new TFPMEntities();
            var          CProfile = context.CustomerProfiles.Where(o => o.CompanyID.Equals(model.CompanyID)).FirstOrDefault();

            if (CProfile != null)
            {
                if (RoleNames.Contains(Roles.PortalAdmin) || RoleNames.Contains(Roles.SuperAdmin))
                {
                    //Same Company Data Update
                    if (CProfile.CustomerName == model.CustomerName)
                    {
                        CProfile.CompanyLogo       = CommonFunctions.Trimstring(model.CompanyLogo);
                        CProfile.AccountOwnerEmail = CommonFunctions.Trimstring(model.AccountOwnerEmail);
                        CProfile.AccountOwnerName  = CommonFunctions.Trimstring(model.AccountOwnerName);
                        CProfile.AddressLine1      = CommonFunctions.Trimstring(model.AddressLine1);
                        CProfile.AddressLine2      = CommonFunctions.Trimstring(model.AddressLine2);
                        CProfile.City       = CommonFunctions.Trimstring(model.City);
                        CProfile.State      = CommonFunctions.Trimstring(model.State);
                        CProfile.ZipCode    = CommonFunctions.Trimstring(model.ZipCode);
                        CProfile.ModifiedOn = DateTime.Now;
                        CProfile.ModifiedBy = UserID;
                        CProfile.isActive   = model.isActive;
                    }
                    else
                    {
                        //New company data Update
                        if (!context.CustomerProfiles.Where(o => o.CustomerName == model.CustomerName).Any())
                        {
                            CProfile.CustomerName      = CommonFunctions.Trimstring(model.CustomerName);
                            CProfile.CompanyLogo       = CommonFunctions.Trimstring(model.CompanyLogo);
                            CProfile.AccountOwnerEmail = CommonFunctions.Trimstring(model.AccountOwnerEmail);
                            CProfile.AccountOwnerName  = CommonFunctions.Trimstring(model.AccountOwnerName);
                            CProfile.AddressLine1      = CommonFunctions.Trimstring(model.AddressLine1);
                            CProfile.AddressLine2      = CommonFunctions.Trimstring(model.AddressLine2);
                            CProfile.City       = CommonFunctions.Trimstring(model.City);
                            CProfile.State      = CommonFunctions.Trimstring(model.State);
                            CProfile.ZipCode    = CommonFunctions.Trimstring(model.ZipCode);
                            CProfile.ModifiedOn = DateTime.Now;
                            CProfile.ModifiedBy = UserID;
                            CProfile.isActive   = model.isActive;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    CProfile.AddressLine1 = CommonFunctions.Trimstring(model.AddressLine1);
                    CProfile.AddressLine2 = CommonFunctions.Trimstring(model.AddressLine2);
                    CProfile.City         = CommonFunctions.Trimstring(model.City);
                    CProfile.State        = CommonFunctions.Trimstring(model.State);
                    CProfile.ZipCode      = CommonFunctions.Trimstring(model.ZipCode);
                    CProfile.ModifiedOn   = DateTime.Now;
                    CProfile.ModifiedBy   = UserID;
                }
                context.SaveChanges();
                var CustomerDTO = new CustomerProfileDTO
                {
                    CompanyID         = CProfile.CompanyID,
                    CustomerName      = CProfile.CustomerName,
                    City              = CProfile.City,
                    State             = CProfile.State,
                    AccountNumber     = CProfile.AccountNumber,
                    AccountOwnerEmail = CProfile.AccountOwnerEmail,
                    AccountOwnerName  = CProfile.AccountOwnerName,
                    AddressLine1      = CProfile.AddressLine1,
                    AddressLine2      = CProfile.AddressLine2,
                    ZipCode           = CProfile.ZipCode,
                    CompanyLogo       = CProfile.CompanyLogo,
                    CreatedOn         = CProfile.CreatedOn,
                    DotCount          = CProfile.CustomerDOTNumbers.Count(a => a.IsDelete == false),
                    UserCount         = CProfile.AspNetUsers.Count(a => a.IsActive == true),
                    ModifiedOn        = CProfile.ModifiedOn,
                    isActive          = CProfile.isActive,
                    CreatedBy         = CProfile.CreatedBy,
                    ModifiedBy        = CProfile.ModifiedBy
                };
                return(CustomerDTO);
            }
            else
            {
                return(null);
            }
        }