コード例 #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));
            }
        }