コード例 #1
0
        public BaseOutput AddProviderWithUser(Provider item, out Provider itemOut)
        {
            CRUDOperation cRUDOperation = new CRUDOperation();
            BaseOutput    baseOutput;

            try
            {
                if ((string.IsNullOrEmpty(item.VOEN)) || (item.VOEN.Length != 10))
                {
                    itemOut = null;
                    return(baseOutput = new BaseOutput(true, CustomError.VOENNotStandartErrorCode, CustomError.VOENNotStandartErrorDesc, ""));
                }

                tbl_EnumValue enumValue = cRUDOperation.GetEnumValueByName("Provider");

                tbl_User user = new tbl_User()
                {
                    UserName      = item.UserName,
                    Password      = UserUtil.MD5HashedPassword(item.Password),
                    UserType_EVID = enumValue.ID,
                };

                tbl_User _User = cRUDOperation.GetUserByUserName(user.UserName);
                if (_User == null)
                {
                    tbl_Provider providerVoen = cRUDOperation.GetProviderByVOEN(item.VOEN);
                    if (providerVoen != null)
                    {
                        itemOut = null;
                        return(baseOutput = new BaseOutput(true, CustomError.UniqueVOENErrorCode, CustomError.UniqueVOENErrorDesc, ""));
                    }
                    tbl_User userDB = cRUDOperation.AddUser(user);
                    if (userDB != null)
                    {
                        tbl_Provider provider = new tbl_Provider()
                        {
                            UserId                  = userDB.ID,
                            Name                    = item.Name,
                            Type                    = item.Type,
                            Description             = item.Description,
                            RegionId                = item.RegionId,
                            Address                 = item.Address,
                            RelatedPersonName       = item.RelatedPersonName,
                            RelatedPersonPhone      = item.RelatedPersonPhone,
                            RelatedPersonProfession = item.RelatedPersonProfession,
                            RP_HomePhone            = item.RP_HomePhone,
                            VOEN                    = item.VOEN,
                            ParentID                = item.ParentID
                        };
                        tbl_Provider providerDB = cRUDOperation.AddProvider(provider);

                        if (providerDB != null)
                        {
                            itemOut = new Provider()
                            {
                                UserID                  = providerDB.UserId,
                                UserName                = userDB.UserName,
                                ID                      = providerDB.ID,
                                ParentID                = providerDB.ParentID,
                                Name                    = providerDB.Name,
                                Type                    = providerDB.Type == null ? 0 : (Int64)providerDB.Type,
                                Description             = providerDB.Description,
                                RegionId                = providerDB.RegionId == null ? 0 : (Int64)providerDB.RegionId,
                                RelatedPersonName       = providerDB.RelatedPersonName,
                                RelatedPersonPhone      = providerDB.RelatedPersonPhone,
                                RelatedPersonProfession = providerDB.RelatedPersonProfession,
                                RP_HomePhone            = providerDB.RP_HomePhone,
                                VOEN                    = providerDB.VOEN
                            };
                            return(baseOutput = new BaseOutput(true, BOResultTypes.Success.GetHashCode(), BOBaseOutputResponse.SuccessResponse, ""));
                        }
                        else
                        {
                            itemOut = null;
                            return(baseOutput = new BaseOutput(true, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ""));
                        }
                    }
                    else
                    {
                        itemOut = null;
                        return(baseOutput = new BaseOutput(true, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ""));
                    }
                }
                else
                {
                    itemOut = null;
                    return(baseOutput = new BaseOutput(true, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ""));
                }
            }
            catch (Exception ex)
            {
                itemOut = null;
                return(baseOutput = new BaseOutput(false, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ex.Message));
            }
        }
コード例 #2
0
        public BaseOutput AddCustomerWithUser(Customer item, out Customer itemOut)
        {
            CRUDOperation cRUDOperation = new CRUDOperation();
            BaseOutput    baseOutput;

            itemOut = null;
            try
            {
                tbl_EnumValue enumValue = cRUDOperation.GetEnumValueByName("Customer");

                tbl_User user = new tbl_User()
                {
                    UserName      = item.UserName,
                    Password      = UserUtil.MD5HashedPassword(item.Password),
                    UserType_EVID = enumValue.ID,
                };
                tbl_User _User = cRUDOperation.GetUserByUserName(user.UserName);
                if (_User == null)
                {
                    tbl_User userDB = cRUDOperation.AddUser(user);
                    if (userDB != null)
                    {
                        tbl_Customer customer = new tbl_Customer()
                        {
                            UserId       = userDB.ID,
                            Name         = item.Name,
                            Surname      = item.Surname,
                            FatherName   = item.FatherName,
                            IdentityCode = item.IdentityCode,
                            PhoneNumber  = item.PhoneNumber,
                            Email        = item.Email,
                            RegionId     = item.RegionId,
                            Address      = item.Address
                        };
                        tbl_Customer customerDB = cRUDOperation.AddCustomer(customer);

                        if (customerDB != null)
                        {
                            itemOut = new Customer()
                            {
                                UserID       = customerDB.UserId,
                                UserName     = userDB.UserName,
                                CustomerID   = customerDB.ID,
                                Name         = customerDB.Name,
                                Surname      = customerDB.Surname,
                                FatherName   = customerDB.FatherName,
                                IdentityCode = customerDB.IdentityCode,
                                PhoneNumber  = customerDB.PhoneNumber,
                                Email        = customerDB.Email,
                                RegionId     = customerDB.RegionId == null ? 0 : (Int64)customerDB.RegionId,
                                Address      = customerDB.Address
                            };
                        }
                    }
                }

                return(baseOutput = new BaseOutput(true, BOResultTypes.Success.GetHashCode(), BOBaseOutputResponse.SuccessResponse, ""));
            }
            catch (Exception ex)
            {
                return(baseOutput = new BaseOutput(false, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ex.Message));
            }
        }