public ResultObject ValidateCustomerDetail(CustomerHeadDto customerDto, ResultObject resultObject)
        {
            if (customerDto.MobileCustomerDetail.Value == null)
            {
                resultObject.ServerErrors.Add(new ServerErr()
                {
                    Hint = "پر کردن موبایل مشتری الزامی است"
                });
                return(resultObject);
            }

            if (customerDto.HomeAddressCustomerDetail.Value == null)
            {
                resultObject.ServerErrors.Add(new ServerErr()
                {
                    Hint = "پر کردن فیلد آدرس منزل الزامی است"
                });
                return(resultObject);
            }

            if (customerDto.HomePhoneCustomerDetail.Value == null)
            {
                resultObject.ServerErrors.Add(new ServerErr()
                {
                    Hint = "پر کردن فیلد  تلفن منزل الزامی است"
                });
                return(resultObject);
            }

            return(resultObject);
        }
        public async Task <CustomerHeadDto> GetCustomerByUserIDAsync(int userID)
        {
            var customerInfo = await _customerService.GetCustomerByUserIDAsync(userID);

            CustomerHeadDto result = new CustomerHeadDto();

            result = _mapper.Map <CustomerHeadDto>(customerInfo);

            return(result);
        }
Ejemplo n.º 3
0
 public async Task <ResultObject> SetAsync([FromBody] CustomerHeadDto customerDto)
 {
     if (customerDto.ID == 0)
     {
         return(await customerAppService.CreateCustomerAsync(customerDto));
     }
     else
     {
         return(await customerAppService.UpdateCustomerAsync(customerDto));
     }
 }
Ejemplo n.º 4
0
        public async Task <ResultObject> GetCustomerInfoByNationalCodeAsync(string nationalCode, string birthDate)
        {
            List <ServerErr> errors       = null;
            CustomerHeadDto  cust         = new CustomerHeadDto();
            ResultObject     resultObject = new ResultObject();

            try
            {
                var result = await client.GetPersonInfoAsync(nationalCode, birthDate, "microfunds", "micro#Funds@");

                if (result != null)
                {
                    cust.FirstName  = result.Body.GetPersonInfoResult?.Name;
                    cust.LastName   = result.Body.GetPersonInfoResult?.Family;
                    cust.FatherName = result.Body.GetPersonInfoResult?.FatherName;
                    cust.SSH        = result.Body.GetPersonInfoResult?.ShenasnameNo;
                    cust.SeriNo     = result.Body.GetPersonInfoResult?.ShenasnameSerial;
                    cust.SeriChar   = result.Body.GetPersonInfoResult?.ShenasnameSeri;
                }
                else
                {
                    if (errors == null)
                    {
                        errors = new List <ServerErr>();
                    }
                    errors.Add(new ServerErr()
                    {
                        Hint = "فردی با مشخصات وارد شده یافت نشد"
                    });
                    resultObject.Result       = null;
                    resultObject.ServerErrors = errors;
                    return(resultObject);
                }
            } catch
            {
                if (errors == null)
                {
                    errors = new List <ServerErr>();
                }
                errors.Add(new ServerErr()
                {
                    Hint = "فردی با مشخصات وارد شده یافت نشد"
                });
                resultObject.Result       = null;
                resultObject.ServerErrors = errors;
                return(resultObject);
            }

            resultObject.Result       = cust;
            resultObject.ServerErrors = null;

            return(resultObject);
        }
        public async Task <ResultObject> UploadFiles([FromForm] ICollection <IFormFile> filess)
        {
            var resultobject = new ResultObject();

            var           files         = Request.Form.Files;
            string        attachmentDto = Request.Form["attachmentDto"];
            string        dtoName       = Request.Form["dtoName"];
            AttachmentDto attDto        = Newtonsoft.Json.JsonConvert.DeserializeObject <AttachmentDto>(attachmentDto);

            attDto.File = files[0];

            if (files.Any(f => f.Length == 0))
            {
                return(new ResultObject {
                    Result = attDto, ServerErrors = null                       /*new List<ServerErr>().Add(new ServerErr() { Hint = "هیچ فایلی فرستاده نشده است" })*/
                });
            }

            if (attDto.AttachmentTypeID == 0)
            {
                resultobject.ServerErrors.Add(new ServerErr()
                {
                    Hint = "نوع فایل را وارد کنید"
                });
                return(resultobject);
            }

            string entity = attDto.entity.ToString();

            if (dtoName == ConstAttachmentTypeCategory.Customer.ToString())
            {
                CustomerHeadDto customerDto = Newtonsoft.Json.JsonConvert.DeserializeObject <CustomerHeadDto>(entity);
                attDto.CustomerHeadID = customerDto.ID;
                attDto.Path           = await _uploadAppService.CreateDirectoryAndFile(attDto.CustomerHeadID.Value, "CustomerDto", attDto.File);
            }

            else if (dtoName == ConstAttachmentTypeCategory.User.ToString())
            {
                UserDto userDto = Newtonsoft.Json.JsonConvert.DeserializeObject <UserDto>(entity);
                attDto.UserID = userDto.ID;
                attDto.Path   = await _uploadAppService.CreateDirectoryAndFile(attDto.UserID.Value, "UserDto", attDto.File);
            }



            await _uploadAppService.CreateAttachmentAsync(attDto);

            resultobject.Result       = attDto;
            resultobject.ServerErrors = null;

            return(resultobject);
        }
        public async Task <CustomerHeadDto> GetCustomerAsync(int customerNumber)
        {
            var customerInfo = await _customerService.GetCustomerAsync(customerNumber);

            CustomerHeadDto result = new CustomerHeadDto();

            result = _mapper.Map <CustomerHeadDto>(customerInfo);

            result.CustomerDetails = new List <CustomerDetailDto>();


            customerInfo.CustomerDetails.ForEach(x =>
            {
                result.CustomerDetails.Add(new CustomerDetailDto()
                {
                    Code  = x.CustomerDetailType.Code,
                    Value = x.Value,
                    ID    = x.ID
                });
            });
            return(result);
        }
        //public async Task<Account> CreateAccountAsync(AccountDto accountDto)
        //{
        //    //باز کردن موقتی حساب
        //    accountDto.AccountStatusID = ConstAccountStatuses.Open;

        //    Branch branch = await branchAppService._branchService.GetBranchAsync(accountDto.BranchID);

        //    accountDto.BranchCode = branch.BranchCode;
        //    var account = mapper.Map<Account>(accountDto);
        //    await accountService.CreateAccountAsync(account);

        //    var result = await transactionManager.SaveAllAsync();

        //    return account;
        //}


        public async Task <ResultObject> UpdateCustomerAsync(CustomerHeadDto customerDto)
        {
            ResultObject resultObject = new ResultObject();

            customerDto.FillCustomerDetail();
            var customerHead = _mapper.Map <CustomerHead>(customerDto);

            // بروز رسانی جزئیات مشتری
            foreach (var detail in customerHead.CustomerDetails)
            {
                if (detail.ID != 0)
                {
                    var customerDetailTask = await _customerService.UpdateCustomerDetailsAsync(detail);
                }
                else
                {
                    await _customerService.AddCustomerDetailsAsync(detail);
                }
            }

            foreach (var skill in customerDto.Skills)
            {
                customerHead.CustomerSkills.Add(new CustomerSkill()
                {
                    CustomerID = customerHead.ID, SkillID = skill
                });
            }
            await _customerService.UpdateCustomerSkills(customerHead.CustomerSkills, customerHead.ID);

            var customerHeadTask = await _customerService.UpdateCustomerAsync(customerHead);

            await _transactionManager.SaveAllAsync();

            resultObject.Result       = customerHeadTask.Serial;
            resultObject.ServerErrors = null;
            return(resultObject);
        }
        public async Task <ResultObject> CreateCustomerAsync(CustomerHeadDto customerDto)
        {
            ResultObject result = new ResultObject();
            var          cu     = await _customerService.GetCustomerByNationalCodeAndBranchIDAsync(customerDto.NationalCode);

            if (cu != null)
            {
                result.ServerErrors.Add(new ServerErr()
                {
                    Hint = "کد ملی مشتری نمیتواند تکراری باشد"
                });
                return(result);
            }
            customerDto.FillCustomerDetail();
            result = ValidateCustomerDetail(customerDto, result);
            if (result.ServerErrors.Count > 0)
            {
                return(result);
            }

            var customer = _mapper.Map <CustomerHead>(customerDto);

            if (customerDto.Skills != null && customerDto.Skills.Count > 0)
            {
                foreach (var skillID in customerDto.Skills)
                {
                    customer.CustomerSkills.Add(new CustomerSkill()
                    {
                        SkillID = skillID
                    });
                }
            }

            var mainUser = await _userAppService.GetUserByNationalCodeAsync(customerDto.NationalCode);

            User user = new User();
            IDbContextTransaction transaction;

            if (mainUser == null)
            {
                user.FirstName           = customerDto.FirstName;
                user.LastName            = customerDto.LastName;
                user.UserName            = customerDto.NationalCode;
                user.NationalCode        = customerDto.NationalCode;
                user.IsActive            = true;
                user.IsRequireChangePass = true;
                user.Password            = "******";

                UserBranches userBranch = new UserBranches()
                {
                    BranchId = customerDto.BranchID, UserId = user.ID
                };
                UserBranchRole userBranchRole = new UserBranchRole()
                {
                    BranchId = customerDto.BranchID, UserId = user.ID, RoleId = ConstRoles.Customer
                };
                user.UserBranches.Add(userBranch);
                user.UserBranchRoles.Add(userBranchRole);
                transaction = await _userService.CreateUserByUserBranchAsync(user);

                await _transactionManager.SaveAllAsync();

                customer.CustomerUserID = user.ID;
                await _customerService.CreateCustomerAsync(customer);

                var res = await _transactionManager.SaveAllAsync();

                transaction.Commit();
            }
            else
            {
                if (result.ServerErrors.Count > 0)
                {
                    return(result);
                }
                customer.CustomerUserID = mainUser.ID;
                await _customerService.CreateCustomerAsync(customer);

                var res = await _transactionManager.SaveAllAsync();
            }

            if (customer.IsMale)
            {
                _notificationAppService.SendMessage($"جناب آقای {customer.FirstName + " " + customer.LastName} " +
                                                    $"{Environment.NewLine} اطلاعات شما با شماره مشتری {customer.Serial} در سامانه صندوق های خرد محلی {customerDto.BranchName} ثبت گردید {Environment.NewLine} نام کاربری {user.UserName}",
                                                    customerDto.MobileCustomerDetail.Value);
            }
            else
            {
                _notificationAppService.SendMessage($"سرکار خانم {customer.FirstName + " " + customer.LastName} {Environment.NewLine} اطلاعات شما با شماره مشتری {customer.Serial} در سامانه صندوق های خرد محلی {customerDto.BranchName} ثبت گردید {Environment.NewLine} نام کاربری {user.UserName}",
                                                    customerDto.MobileCustomerDetail.Value);
            }

            result.Result       = customer.Serial;
            result.ServerErrors = null;
            return(result);
        }