Example #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [StorageAccount("StorageConnectionString")] CloudStorageAccount storageAccount,
            TraceWriter log
            )
        {
            try {
                var ip = IpUtility.GetClientIp(req);
                log.Info($"User {ip} is attempting to authenticate a token");
                var    client       = storageAccount.CreateCloudTableClient();
                string partitionKey = await Authenticator.Authenticate(client, req);


                if (string.IsNullOrEmpty(partitionKey))
                {
                    log.Warning($"{ip}: Authentication failure");
                    return(new UnauthorizedResult());
                }
                else
                {
                    log.Info($"{ip}: Authentication success");
                    return(new OkResult());
                }
            }
            catch (Exception ex) {
                log.Error("Unhandlex exception while processing request");
                log.Error(ex.Message, ex);
                return(new InternalServerErrorResult());
            }
        }
Example #2
0
        /// <summary>
        /// 发布动态
        /// </summary>
        /// <param name="item"></param>
        /// <returns>返回动态id 小于0 则失败</returns>
        public virtual int DynamicAdd(DynamicModel item)
        {
            DbCommand cmd = GetStoredProcCommand("P_Dynamic_Add");

            AddInParameter(cmd, "@UserId", DbType.Int32, item.UserId);
            AddInParameter(cmd, "@Type", DbType.Int32, item.Type);
            AddInParameter(cmd, "@Title", DbType.String, item.Title);
            AddInParameter(cmd, "@DynamicContent", DbType.String, item.DynamicContent);
            AddInParameter(cmd, "@Ip", DbType.String, IpUtility.GetIp());
            AddInParameter(cmd, "@Lat", DbType.Decimal, item.Lat);
            AddInParameter(cmd, "@Lng", DbType.Decimal, item.Lng);
            AddInParameter(cmd, "@CityId", DbType.Int32, item.CityId);
            AddInParameter(cmd, "@Location", DbType.String, item.Location);
            if (item.ImageList != null && item.ImageList.Count > 0)
            {
                AddInParameter(cmd, "@Images", DbType.Xml, XmlUtility.Serialize(item.ImageList, Encoding.UTF8, "Images"));
            }
            AddInParameter(cmd, "@Visible", DbType.Int32, item.Visible);
            AddInParameter(cmd, "@IsMentionAll", DbType.Int32, item.IsMentionAll);
            AddOutParameter(cmd, "@DynamicId", DbType.Int32, 4);
            ExecuteNonQuery(cmd);
            int outId = 0;

            int.TryParse(cmd.Parameters["@DynamicId"].Value.ToString(), out outId);
            return(outId);
        }
Example #3
0
        void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;

            if (application == null)
            {
                return;
            }

            HttpContext context = application.Context;

            if (string.IsNullOrEmpty(context.Request.UserAgent))
            {
                Inspect(context, BlockType.Forbidden, string.Empty);
            }

            if (!UserAgentUtility.IsSearchEngine(context.Request))
            {
                SiteGuardRules rules = GetRules(context);

                foreach (var rule in rules)
                {
                    if (context.Request.Url.AbsolutePath.StartsWith(rule.Path, StringComparison.OrdinalIgnoreCase) && ("ALL".Equals(rule.HttpMethod, StringComparison.OrdinalIgnoreCase) || context.Request.HttpMethod.Equals(rule.HttpMethod, StringComparison.OrdinalIgnoreCase)))
                    {
                        string keyBase = rule.HttpMethod.ToLower() + "_" + rule.Path.ToLower() + "_" +
                                         IpUtility.GetIp();
                        string countKey = keyBase + "_Count";
                        string blockKey = keyBase + "_Block";

                        if (context.Cache[blockKey] != null)
                        {
                            Inspect(context, rule.BlockType, rule.Message);
                            return;
                        }


                        object obj = context.Cache[countKey];
                        if (obj == null)
                        {
                            context.Cache.Add(countKey, new Counter {
                                Count = 1
                            }, null, DateTime.Now.AddSeconds(rule.TimePeriod), Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, null);
                        }
                        else
                        {
                            Counter counter = (Counter)obj;

                            counter.Count++;

                            if (counter.Count > rule.MaxRequests)
                            {
                                context.Cache.Add(blockKey, true, null, DateTime.Now.AddSeconds(rule.BlockTime), Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, null);
                                Inspect(context, rule.BlockType, rule.Message);
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        public virtual int HomeIndexAccessStat(int userId, string name)
        {
            DbCommand cmd = GetStoredProcCommand("P_Api_HomeIndexAccessStat");

            AddInParameter(cmd, "@userId", DbType.Int32, userId);
            AddInParameter(cmd, "@name", DbType.String, name);
            AddInParameter(cmd, "@ip", DbType.String, IpUtility.GetIp());
            return(ExecuteNonQuery(cmd));
        }
Example #5
0
        private static ActionLog BuildActionLog(HttpRequest request)
        {
            ActionLog log = new ActionLog()
            {
                Host         = request.Url.Host,
                PathAndQuery = request.Url.PathAndQuery,
                Server       = Environment.MachineName,
                UserAgent    = request.UserAgent,
                IpAddress    = IpUtility.GetIp(),
                AccessTime   = DateTime.Now,
                HttpMethod   = request.HttpMethod
            };

            return(log);
        }
Example #6
0
        public static IActionResult Run
            ([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            log.Info($"C# HTTP trigger function processed a request by {IpUtility.GetClientIp(req)}.");

            string name = req.Query["name"];

            string  requestBody = new StreamReader(req.Body).ReadToEnd();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            return(name != null
                ? (ActionResult) new OkObjectResult($"Hello, {name}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
        }
Example #7
0
        /// <summary>
        /// 连接服务,仅允许内网IP连接本服务
        /// </summary>
        /// <param name="identityName">标识名称,例如用户的域登陆名称</param>
        /// <returns>是否允许连接管理服务</returns>
        public bool Connect(string identityName)
        {
            string logFileName = base.CurrentContext.Host.LogDirectory + "ManageLog.txt";

            WriteLogFile(logFileName, identityName + " 连接服务器;");
            string    ip  = base.CurrentContext.Request.ClientIP;
            IpUtility ipu = new IpUtility();

            if (!ipu.IsInner(ip))
            {
                WriteLogFile(logFileName, ip + " [拒绝]该IP连接服务器;");
                return(false);
            }
            WriteLogFile(logFileName, ip + " [允许]该IP连接服务器;");
            return(true);
        }
Example #8
0
        public virtual PublicUserModel PublicUserAdminLogin(string loginName, string pwd, int isAddLog = 1)
        {
            string    passWordAdorn = ConfigUtility.GetValue("PassWordAdorn");
            DbCommand cmd           = GetStoredProcCommand("P_Api_PublicUserAdminLogin");

            AddInParameter(cmd, "@loginName", DbType.String, loginName);
            AddInParameter(cmd, "@ip", DbType.String, IpUtility.GetIp());
            AddInParameter(cmd, "@pwd", DbType.String, StringUtility.ToMd5String(passWordAdorn + pwd));
            AddInParameter(cmd, "@isAddLog", DbType.Int32, isAddLog);
            DataSet ds = ExecuteDataSet(cmd);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return(BulidPublicUser(ds.Tables[0].Rows[0]));
            }
            return(null);
        }
        private static ApiLogModel BuildApiLog(HttpRequest request)
        {
            ApiLogModel log = new ApiLogModel()
            {
                Hash         = request.Headers["Hash"],
                Token        = request.Headers["Token"],
                Host         = request.Url.Host,
                PathAndQuery = request.Url.PathAndQuery,
                Server       = Environment.MachineName,
                UserAgent    = request.UserAgent,
                IpAddress    = IpUtility.GetIp(),
                IMEI         = request.Headers["IMEI"],
                Device       = request.Headers["Device"],
                OsVersion    = request.Headers["OsVersion"],
                MacAddress   = request.Headers["MacAddress"]
            };

            return(log);
        }
Example #10
0
        public virtual Credential PostLogin(string loginName, string password, int loginType, out int returnValue)
        {
            string    passWordAdorn = ConfigUtility.GetValue("PassWordAdorn");
            DbCommand cmd           = GetStoredProcCommand("P_Client_Login");

            AddInParameter(cmd, "LoginName", DbType.String, loginName);
            AddInParameter(cmd, "Password", DbType.String, StringUtility.ToMd5String(passWordAdorn + password));
            AddInParameter(cmd, "Token", DbType.String, StringUtility.NewGuidString());
            AddInParameter(cmd, "ExpirationDate", DbType.DateTime, DateTime.Now.AddMonths(6));
            AddInParameter(cmd, "IP", DbType.String, IpUtility.GetIp());
            AddInParameter(cmd, "LoginType", DbType.Int32, loginType);
            AddOutParameter(cmd, "@returnValue", DbType.Int32, 0);
            var ds = ExecuteDataSet(cmd);

            returnValue = GetOutputParameter <Int32>(cmd, "@ReturnValue");
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }
            return(BuildCredential(ds.Tables[0]));
        }
Example #11
0
        public ActionResult OperateHouse(FormCollection form)
        {
            PublicUserModel loginUser = this.GetLoginUser();

            #region 基本信息
            int houseId = 0, buildingType, city, uid = loginUser.UserID;
            int.TryParse(form["houseId"], out houseId);           //房源ID
            int.TryParse(form["buildingType"], out buildingType); //房屋类型
            int tradeType;
            int.TryParse(form["postType"], out tradeType);        //发布类型
            int isChange = 0;
            int.TryParse(form["isChange"], out isChange);         //表单是否被修改

            int.TryParse(form["city"], out city);                 //城市ID
            int communityId;
            int.TryParse(form["cellCode"], out communityId);      // 小区ID
            string communityName = form["cell"];                  //小区名

            int distrct;
            int.TryParse(form["distrct"], out distrct);  //行政区

            int region;
            int.TryParse(form["area"], out region); //路段

            string address = form["addr"];          //地址

            double buildArea, usedArea;
            double.TryParse(form["houseArea"], out buildArea);  //建筑面积
            double.TryParse(form["areaUsed"], out usedArea);    //使用面积
            if (usedArea > buildArea)
            {
                return(Content("建筑面积必须大于使用面积"));
            }
            int room, hall, kitchen, toilet, balcony;
            int.TryParse(form["room"], out room);       //房
            int.TryParse(form["hall"], out hall);       //厅
            int.TryParse(form["kitchen"], out kitchen); //厨房
            int.TryParse(form["toilet"], out toilet);   //卫生间
            int.TryParse(form["balcony"], out balcony); //阳台

            double price;
            double.TryParse(form["price"], out price); //价格

            double lowpay = 0;                         //最低首付


            string priceUnit;  //价格单位
            double unitPrice = 0;

            switch (tradeType)
            {
            case (int)TradeType.Sell:
                priceUnit = "万";
                unitPrice = buildArea > 0 ? price * 10000 / buildArea : 0; //出售计算单价
                lowpay    = price * 10000 * 0.30;                          //最低首付计算
                ; break;

            case (int)TradeType.Rent:
                switch (buildingType)
                {
                case (int)BuildingType.House:
                case (int)BuildingType.Villa:
                    priceUnit = "元/月"; break;

                default: priceUnit = form["priceType"]; break;
                }
                break;

            default: priceUnit = form["priceType"]; break;
            }

            string payType = form["payType"].IsNoNull() ? form["payType"] : "";  //支付方式

            int usedYear = 0;
            int.TryParse(form["ddlUsedYear"], out usedYear);  //建造年代

            Int16 curFloor = 0;
            Int16.TryParse(form["curFloor"], out curFloor);  //所在楼层

            Int16 maxFloor = 0;
            Int16.TryParse(form["maxFloor"], out maxFloor);  //总层数

            if (curFloor > maxFloor)
            {
                return(Content("总层数必须大于所在楼层"));
            }

            string pointTo = form["pointTo"];                                                           //朝向

            string lookTime      = form["lookTime"];                                                    //看房时间
            string fitmentStatus = form["fitmentStatus"];                                               //装修程度
            string internalNum   = form["internalNum"];                                                 //内部编号
            string cellLabel     = form["cellLabel"];                                                   //小区特色
            string houseLabel    = form["houseLabel"];                                                  //房源标签
            string yijuhua       = form["yijuhua"];                                                     //一句话广告

            string video = form["video"];                                                               //视频
            string title = form["title"].IsNoNull() ? form["title"] : communityName;                    //房源标题

            string contacts      = form["contacts"].IsNoNull() ? form["contacts"] : loginUser.NickName; //委托人
            string tel           = form["tel"].IsNoNull() ? form["tel"] : loginUser.Tel;                //委托人联系方式
            string houseDescribe = form["houseDescribe"];                                               //房源描述

            string imgUrlCover = "";                                                                    //房源图封面

            string imgUrl      = form["imgUrl"].IsNoNull() ? form["imgUrl"] : "";                       //房源图
            string imageType   = form["imageType"].IsNoNull() ? form["imageType"] : "";                 //房源图类型
            string imgDescribe = "," + (form["imgDescribe"].IsNoNull()? form["imgDescribe"] : "");      //房源图说明

            string[] imgUrlLists      = imgUrl.Split(',');
            string[] imageTypeLists   = imageType.Split(',');
            string[] imgDescribeLists = imgDescribe.Split(',');

            if (imgUrlLists.Length > 0 && string.IsNullOrEmpty(imgUrlCover))
            {
                imgUrlCover = imgUrlLists[0];
            }
            //   return JsonReturnValue(new { Message = imgUrl + " | " + imageType + " | " + imgDescribe + " | " + imgUrlCover + " | " + imageTypeCover + " | " + imgDescribeCover, id = houseId, }, JsonRequestBehavior.AllowGet);


            HouseBasicInfo houseBasicInfo = new HouseBasicInfo();
            if (houseId < 1)
            {
                return(Content("管理后台不能发布房源"));
            }
            houseBasicInfo = ncBase.CurrentEntities.HouseBasicInfo.Where(o => o.HouseID == houseId).FirstOrDefault();
            if (houseBasicInfo.IsNull())
            {
                return(Content("该房源不存在"));
            }

            houseBasicInfo.TradeType     = BitConverter.GetBytes(tradeType)[0];
            houseBasicInfo.CityID        = city;
            houseBasicInfo.Distrctid     = distrct;
            houseBasicInfo.RegionID      = region;
            houseBasicInfo.CommunityID   = communityId;
            houseBasicInfo.CommunityName = communityName;
            houseBasicInfo.BuildType     = BitConverter.GetBytes(buildingType)[0];
            houseBasicInfo.BuildArea     = Convert.ToDecimal(buildArea);
            houseBasicInfo.UsedArea      = Convert.ToDecimal(usedArea);;
            houseBasicInfo.PointTo       = pointTo;
            houseBasicInfo.UnitPrice     = Convert.ToDecimal(unitPrice);
            houseBasicInfo.Price         = Convert.ToDecimal(price);
            houseBasicInfo.PriceUnit     = priceUnit;
            houseBasicInfo.CurFloor      = curFloor;
            houseBasicInfo.MaxFloor      = maxFloor;
            houseBasicInfo.UsedYear      = usedYear;
            houseBasicInfo.ExpireDay     = DateTime.Now.AddDays(30);
            houseBasicInfo.FitmentStatus = fitmentStatus;
            int picNum = imgUrlLists.Length > 1 ? imgUrlLists.Length - 1 : 0;
            houseBasicInfo.PicNum        = BitConverter.GetBytes(picNum)[0];
            houseBasicInfo.Title         = title;
            houseBasicInfo.Note          = houseDescribe;
            houseBasicInfo.Status        = BitConverter.GetBytes((int)HouseStatus.Release)[0];
            houseBasicInfo.IP            = IpUtility.GetIp();
            houseBasicInfo.PostTime      = DateTime.Now;
            houseBasicInfo.Address       = address;
            houseBasicInfo.LookHouseTime = lookTime;
            houseBasicInfo.HouseLabel    = houseLabel;
            houseBasicInfo.InternalNum   = internalNum;
            houseBasicInfo.CellLabel     = cellLabel;
            houseBasicInfo.YiJuHua       = yijuhua;
            houseBasicInfo.Room          = BitConverter.GetBytes(room)[0];
            houseBasicInfo.Hall          = BitConverter.GetBytes(hall)[0];
            houseBasicInfo.Kitchen       = BitConverter.GetBytes(kitchen)[0];
            houseBasicInfo.Toilet        = BitConverter.GetBytes(toilet)[0];
            houseBasicInfo.Balcony       = BitConverter.GetBytes(balcony)[0];
            houseBasicInfo.PayType       = payType;
            houseBasicInfo.HouseImgPath  = imgUrlCover;
            houseBasicInfo.LowPay        = Convert.ToDecimal(lowpay);
            houseBasicInfo.Tel           = tel;
            houseBasicInfo.Contacts      = contacts;
            houseBasicInfo.Video         = video;

            if (houseId.Equals(0)) //添加操作时候
            {
                houseBasicInfo.Tag        = "";
                houseBasicInfo.AddDate    = DateTime.Now;
                houseBasicInfo.PushTime   = Convert.ToDateTime("1900-1-1");
                houseBasicInfo.DeleteTime = Convert.ToDateTime("1900-1-1");
                ncBase.CurrentEntities.AddToHouseBasicInfo(houseBasicInfo);
            }
            ncBase.CurrentEntities.SaveChanges();

            houseId = houseBasicInfo.HouseID;
            #endregion

            #region 添加房源图片

            if (imgUrlLists.Length > 0 && imgUrlLists.Length == imageTypeLists.Length &&
                (imgUrlLists.Length == imgDescribeLists.Length) && isChange == 1)
            {
                HouseBll houseBll = new HouseBll();
                houseBll.DelHouseImageByHouseID(houseId, uid);
                for (int i = 0; i < imgUrlLists.Length; i++)
                {
                    bool value = false;
                    if (imgUrlLists.Length > 1)
                    {
                        for (int j = i + 1; j < imgUrlLists.Length; j++)
                        {
                            if (i != j && imgUrlLists[i] == imgUrlLists[j])
                            {
                                value = true;
                            }
                        }
                    }

                    if (value == false && !string.IsNullOrEmpty(imgUrlLists[i]))
                    {
                        bool isCover = false;
                        if (imgUrlCover == imgUrlLists[i])
                        {
                            isCover = true;
                        }
                        HouseImage houseImage = new HouseImage();
                        houseImage.HouseID     = houseId;
                        houseImage.ImagePath   = imgUrlLists[i];
                        houseImage.ImagePos    = imgDescribeLists[i];
                        houseImage.ImageType   = HouseUtility.GetHouseImgType(imageTypeLists[i]);
                        houseImage.IsCover     = isCover;
                        houseImage.OrderID     = i;
                        houseImage.CommunityID = communityId;
                        houseImage.UserID      = uid;
                        houseImage.AddTime     = DateTime.Now;
                        houseImage.Status      = BitConverter.GetBytes(1)[0];;
                        ncBase.CurrentEntities.AddToHouseImage(houseImage);
                        ncBase.CurrentEntities.SaveChanges();
                    }
                }
            }

            #endregion

            bool isAdd = false;
            #region 房屋类型扩展信息
            switch (buildingType)
            {
            case (int)BuildingType.House:

                #region 住宅信息
                string basicEquipHouse = form["basicEquip"].IsNoNull() ? form["basicEquip"] : "";         //住宅基础设施
                string houseType       = form["houseType"].IsNoNull() ? form["houseType"] : "";           //房屋类别
                string houseSubType    = form["houseSubType"].IsNoNull() ? form["houseSubType"] : "";     //住宅子类型
                string houseProperty   = form["houseProperty"].IsNoNull() ? form["houseProperty"] : "";   //房屋产权
                string landYear        = form["landYear"].IsNoNull() ? form["landYear"] : "";             //产权年限
                string houseStructure  = form["houseStructure"].IsNoNull() ? form["houseStructure"] : ""; //房屋结构
                bool   fiveYears       = form["fiveYears"].IsNoNull() && form["fiveYears"] == "1";        //产证满二
                bool   onlyHouse       = form["onlyHouse"].IsNoNull() && form["onlyHouse"] == "1";        //唯一住房
                string advEquip        = form["advEquip"].IsNoNull() ? form["advEquip"] : "";             //配套设施

                HouseInfo houseInfo =
                    ncBase.CurrentEntities.HouseInfo.Where(o => o.HouseID.Equals(houseId)).FirstOrDefault();
                if (houseInfo.IsNull())
                {
                    houseInfo = new HouseInfo();
                    isAdd     = true; //标记为新增加
                }

                houseInfo.HouseID        = houseId;
                houseInfo.HouseType      = houseType;
                houseInfo.HouseSubType   = houseSubType;
                houseInfo.HouseProperty  = houseProperty;
                houseInfo.LandYear       = landYear;
                houseInfo.HouseStructure = houseStructure;
                houseInfo.FiveYears      = fiveYears;
                houseInfo.OnlyHouse      = onlyHouse;
                houseInfo.BasicEquip     = basicEquipHouse;
                houseInfo.AdvEquip       = advEquip;

                if (isAdd)
                {
                    ncBase.CurrentEntities.AddToHouseInfo(houseInfo);
                }
                ncBase.CurrentEntities.SaveChanges();
                #endregion

                break;

            case (int)BuildingType.Villa:

                #region 别墅信息

                string villaType   = form["villaType"].IsNoNull() ? form["villaType"] : "";      //别墅形式
                string hallType    = form["hallType"].IsNoNull() ? form["hallType"] : "";        //厅结构
                string landYear2   = form["landYear2"].IsNoNull() ? form["landYear2"] : "";      //产权年限
                bool   fiveYears2  = form["fiveYears2"].IsNoNull() && form["fiveYears2"] == "1"; //产证满二
                bool   onlyHouse2  = form["onlyHouse2"].IsNoNull() && form["onlyHouse2"] == "1"; //唯一住房
                bool   basement    = form["basement"].IsNoNull() && form["basement"] == "1";     //地下室
                bool   garden      = form["garden"].IsNoNull() && form["garden"] == "1";         //花园
                bool   garage      = form["garage"].IsNoNull() && form["garage"] == "1";         //车库
                bool   parkLot     = form["parkLot"].IsNoNull() && form["parkLot"] == "1";       //停车位
                string basicEquip1 = form["basicEquip1"].IsNoNull() ? form["basicEquip1"] : "";  //配套设施
                string advEquip1   = form["advEquip1"].IsNoNull() ? form["advEquip1"] : "";      //室内设施

                VillaInfo villaInfo =
                    ncBase.CurrentEntities.VillaInfo.Where(o => o.HouseID.Equals(houseId)).FirstOrDefault();
                if (villaInfo.IsNull())
                {
                    villaInfo = new VillaInfo();
                    isAdd     = true; //标记为新增加
                }

                villaInfo.HouseID    = houseId;
                villaInfo.VillaType  = villaType;
                villaInfo.HallType   = hallType;
                villaInfo.LandYear   = landYear2;
                villaInfo.OnlyHouse  = onlyHouse2;
                villaInfo.FiveYears  = fiveYears2;
                villaInfo.Basement   = basement;
                villaInfo.Garden     = garden;
                villaInfo.Garage     = garage;
                villaInfo.ParkLot    = parkLot;
                villaInfo.BasicEquip = basicEquip1;
                villaInfo.AdvEquip   = advEquip1;

                if (isAdd)
                {
                    ncBase.CurrentEntities.AddToVillaInfo(villaInfo);
                }
                ncBase.CurrentEntities.SaveChanges();
                #endregion

                break;

            case (int)BuildingType.Shop:

                #region 商铺信息

                string  shopType    = form["shopType"].IsNoNull() ? form["shopType"] : "";;       //商铺类型
                string  shopStatus  = form["shopStatus"].IsNoNull() ? form["shopStatus"] : "";;   //商铺状态
                string  targetField = form["targetField"].IsNoNull() ? form["targetField"] : "";; //目标业态
                decimal feeShop;
                decimal.TryParse(form["fee2"], out feeShop);                                      //物业费
                bool   divideShop  = form["divide2"].IsNoNull() && form["divide2"] == "1";        //是否分割
                string basicEquip2 = form["basicEquip2"].IsNoNull() ? form["basicEquip2"] : "";   //配套设施

                ShopInfo shopInfo =
                    ncBase.CurrentEntities.ShopInfo.Where(o => o.HouseID.Equals(houseId)).FirstOrDefault();
                if (shopInfo.IsNull())
                {
                    shopInfo = new ShopInfo();
                    isAdd    = true;  //标记为新增加
                }

                shopInfo.HouseID     = houseId;
                shopInfo.ShopType    = shopType;
                shopInfo.ShopStatus  = shopStatus;
                shopInfo.TargetField = targetField;
                shopInfo.Fee         = feeShop;
                shopInfo.Divide      = divideShop;
                shopInfo.BasicEquip  = basicEquip2;


                if (isAdd)
                {
                    ncBase.CurrentEntities.AddToShopInfo(shopInfo);
                }
                ncBase.CurrentEntities.SaveChanges();
                #endregion

                break;

            case (int)BuildingType.Office:

                #region 写字楼信息

                string  officeType  = form["officeType"].IsNoNull() ? form["officeType"] : "";   //写字楼类别
                string  officeLevel = form["officeLevel"].IsNoNull() ? form["officeLevel"] : ""; //写字楼级别
                decimal fee3;
                decimal.TryParse(form["fee3"], out fee3);                                        //物业费
                bool   divide3     = form["divide3"].IsNoNull() && form["divide3"] == "1";       //是否分割
                string basicEquip3 = form["basicEquip3"].IsNoNull() ? form["basicEquip3"] : "";  //配套设施


                OfficeInfo officeInfo =
                    ncBase.CurrentEntities.OfficeInfo.Where(o => o.HouseID.Equals(houseId)).FirstOrDefault();
                if (officeInfo.IsNull())
                {
                    officeInfo = new OfficeInfo();
                    isAdd      = true; //标记为新增加
                }

                officeInfo.HouseID     = houseId;
                officeInfo.OfficeType  = officeType;
                officeInfo.OfficeLevel = officeLevel;
                officeInfo.BasicEquip  = basicEquip3;
                officeInfo.Fee         = fee3;
                officeInfo.Divide      = divide3;


                if (isAdd)
                {
                    ncBase.CurrentEntities.AddToOfficeInfo(officeInfo);
                }
                ncBase.CurrentEntities.SaveChanges();
                #endregion

                break;

            case (int)BuildingType.Factory:

                #region 厂房信息

                string factoryType = form["factoryType"].IsNoNull() ? form["factoryType"] : "";      //厂房类别

                string basicEquip4 = form["basicEquip4"].IsNoNull() ? form["basicEquip4"] : "";      //基础设施


                FactoryInfo factoryInfo =
                    ncBase.CurrentEntities.FactoryInfo.Where(o => o.HouseID.Equals(houseId)).FirstOrDefault();
                if (factoryInfo.IsNull())
                {
                    factoryInfo = new FactoryInfo();
                    isAdd       = true; //标记为新增加
                }

                factoryInfo.HouseID     = houseId;
                factoryInfo.BasicEquip  = basicEquip4;
                factoryInfo.FactoryType = factoryType;

                if (isAdd)
                {
                    ncBase.CurrentEntities.AddToFactoryInfo(factoryInfo);
                }
                ncBase.CurrentEntities.SaveChanges();
                #endregion

                break;
            }
            #endregion

            return(RedirectToAction("GetHouseMainView", new { posttype = tradeType, buildType = buildingType }));
            // return JsonReturnValue(new { Message = "房源提交成功", id = houseId, }, JsonRequestBehavior.AllowGet);
        }
Example #12
0
        public virtual List <ImpHouseResultModel> ImpHouseBatch(List <HouseParame> basicInfoList, List <HouseInfoParame> houseInfoParame,
                                                                List <VillaInfoParame> villaInfoParame, List <ShopInfoParame> shopInfoParame, List <OfficeInfoParame> officeInfoParame,
                                                                List <FactoryInfoParame> factoryInfoParame, List <HouseImgParame> houseImgParameList, int userId)
        {
            #region 逻辑转换
            foreach (HouseParame basicInfo in basicInfoList)
            {
                int houseId = basicInfo.HouseId;
                #region 房源 基础表
                //房源图片相关
                string imgUrlCover = "";
                int    picNum      = basicInfo.HouseImgs.Count;
                if (basicInfo.HouseImgs.IsNoNull() && basicInfo.HouseImgs.Count > 0)
                {
                    var isCoverImg = basicInfo.HouseImgs.Where(o => o.IsCover == true).FirstOrDefault();
                    if (isCoverImg.IsNoNull())
                    {
                        imgUrlCover = isCoverImg.imageUrl;
                    }
                    else
                    {
                        imgUrlCover = basicInfo.HouseImgs.FirstOrDefault().imageUrl;
                    }
                }

                //价格相关
                decimal lowpay = 0; //最低首付
                string  priceUnit;  //价格单位
                decimal unitPrice = 0;

                switch (basicInfo.TradeType)
                {
                case (int)TradeType.Sell:
                    priceUnit = "万";
                    unitPrice = basicInfo.BuildArea > 0 ? basicInfo.Price * 10000 / basicInfo.BuildArea : 0; //出售计算单价
                    lowpay    = basicInfo.Price * 10000 * Convert.ToDecimal(0.30);                           //最低首付计算
                    break;

                case (int)TradeType.Rent:
                    switch (basicInfo.BuildType)
                    {
                    case (int)BuildingType.House:
                    case (int)BuildingType.Villa:
                        priceUnit = "元/月"; break;

                    default:
                        priceUnit = basicInfo.PriceUnit; break;
                    }
                    break;

                default: priceUnit = basicInfo.PriceUnit; break;
                }
                Regex replare = new Regex("\\&[lr]dquo;");
                basicInfo.UnitPrice    = unitPrice;
                basicInfo.PriceUnit    = priceUnit;
                basicInfo.LowPay       = lowpay;
                basicInfo.ExpireDay    = DateTime.Now.AddDays(30);
                basicInfo.PicNum       = picNum;
                basicInfo.Note         = replare.Replace(basicInfo.Note, "\"");
                basicInfo.Status       = (int)HouseStatus.Release;
                basicInfo.IP           = IpUtility.GetIp();
                basicInfo.PostTime     = DateTime.Now;
                basicInfo.HouseImgPath = imgUrlCover;

                if (houseId.Equals(0)) //添加操作时候
                {
                    basicInfo.IsClone = basicInfo.IsClone.IsNull() ? false : basicInfo.IsClone;
                    basicInfo.Tag     = "";
                }
                #endregion
                List <HouseImgParame> thisImageList = houseImgParameList.Where(s => s.IndexPoint == basicInfo.IndexPoint).ToList();
                if (thisImageList.IsNoNull() && thisImageList.Count > 0)
                {
                    int i = 1;
                    foreach (HouseImgParame item in basicInfo.HouseImgs)
                    {
                        item.HouseID     = houseId;
                        item.ImagePath   = item.imageUrl;
                        item.ImagePos    = item.imgDescribe;
                        item.OrderID     = i;
                        item.AddTime     = DateTime.Now;
                        item.Status      = 1;
                        item.CommunityID = basicInfo.CommunityId;
                        item.UserID      = basicInfo.UserId;
                        item.ImageType   = item.ImageType;
                        i++;
                    }
                }
            }
            #endregion
            return(houseDal.ImpHouseBatch(basicInfoList, houseInfoParame, villaInfoParame, shopInfoParame, officeInfoParame,
                                          factoryInfoParame, houseImgParameList, userId));
        }
Example #13
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", "options", Route = null)] HttpRequest req,
            [StorageAccount("StorageConnectionString")] CloudStorageAccount storageAccount,
            TraceWriter log
            )
        {
            var email = req.Query["email"].FirstOrDefault()?.ToLower();

            if (string.IsNullOrWhiteSpace(email))
            {
                return(new BadRequestObjectResult("The query parameter \"email\" is empty or missing"));
            }

            log.Info($"E-mail verification request received for {email}");
            var client          = storageAccount.CreateCloudTableClient();
            var throttleService = new ThrottleService(client, log);
            var throttled       = (await throttleService.ThrottleOrIncrement(email)) || (await throttleService.ThrottleOrIncrement(IpUtility.GetClientIp(req)));

            if (throttled)
            {
                return(new StatusCodeResult(429));
            }

            var code  = $"{new Random().Next(100, 999)}{new Random().Next(100, 999)}{new Random().Next(100, 999)}";
            var token = Guid.NewGuid().ToString().Replace("-", "");
            var auth  = new EmailAuthToken(email, token, code)
            {
                Expiration = DateTimeOffset.UtcNow.AddHours(4),
            };

            var secret = Environment.GetEnvironmentVariable("email-secret", EnvironmentVariableTarget.Process);

            if (Upload(log, "http://grimdawn.dreamcrash.org/ia/backup/auth.php", $"token={secret}&target={email}&code={code}"))
            {
                var table = client.GetTableReference(EmailAuthToken.TableName);
                await table.CreateIfNotExistsAsync();

                await table.ExecuteAsync(TableOperation.Insert(auth));

                log.Info($"Successfully posted email for {email}");
            }

            return(new OkObjectResult(new ResponseDto {
                Token = token
            }));
        }
Example #14
0
 public static IPLocation IpSearch(this IHostingEnvironment env, string ip)
 {
     return(IpUtility.IpSearch(env, ip));
 }
Example #15
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", "options", Route = null)] HttpRequest req,
            [StorageAccount("StorageConnectionString")] CloudStorageAccount storageAccount,
            TraceWriter log
            )
        {
            var token  = req.Query["token"];
            var code   = req.Query["code"];
            var client = storageAccount.CreateCloudTableClient();

            if (string.IsNullOrWhiteSpace(token))
            {
                return(new BadRequestObjectResult("The query parameter \"token\" is empty or missing"));
            }
            else if (string.IsNullOrWhiteSpace(code))
            {
                return(new BadRequestObjectResult("The query parameter \"code\" is empty or missing"));
            }

            log.Info($"E-mail verification request received for {token}");

            // Throttling required for verification as well, to prevent infinite attempts on a token.
            var throttleService = new ThrottleService(storageAccount.CreateCloudTableClient(), log);
            var throttled       = (await throttleService.ThrottleOrIncrement("attempt-" + token)) || (await throttleService.ThrottleOrIncrement("attempt-" + IpUtility.GetClientIp(req)));

            if (throttled)
            {
                return(new StatusCodeResult(429));
            }

            var table = client.GetTableReference(EmailAuthToken.TableName);
            await table.CreateIfNotExistsAsync();

            var query = TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, token),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, code)
                );
            var exQuery = new TableQuery <EmailAuthToken>().Where(query);

            var entry = await QueryHelper.Get(table, exQuery);

            if (entry != null)
            {
                if (DateTimeOffset.UtcNow < entry.Expiration)
                {
                    log.Info($"Authentication successful for {entry.Email}");

                    var auth = new Authentication {
                        PartitionKey = Authentication.PartitionName,
                        RowKey       = (Guid.NewGuid().ToString() + Guid.NewGuid().ToString()).Replace("-", ""),
                        Identity     = entry.Email
                    };

                    var authTable = client.GetTableReference(Authentication.TableName);
                    await authTable.CreateIfNotExistsAsync();

                    await authTable.ExecuteAsync(TableOperation.Insert(auth));

                    return(new OkObjectResult(new VerifyEmailTokenResponseDto {
                        Success = true,
                        Token = auth.RowKey
                    }));
                }
                else
                {
                    log.Info($"Authentication token {token} for {entry.Email} has already expired, expiration {entry.Expiration}");

                    return(new OkObjectResult(new VerifyEmailTokenResponseDto {
                        Success = false
                    }));
                }
            }
            else
            {
                log.Info("No entry found");
                return(new OkObjectResult(new VerifyEmailTokenResponseDto {
                    Success = false
                }));
            }
        }
Example #16
0
 public static IPLocation IpSearch(this IHostingEnvironment env, HttpContext httpContext)
 {
     return(IpUtility.IpSearch(env, httpContext));
 }
Example #17
0
 public ApiResult <string> GetIp() => new ApiResult <string>(APIResultCode.Success, IpUtility.GetLocalIP());