Ejemplo n.º 1
0
 /// <summary>
 /// Создать товар
 /// </summary>
 /// <param name="good">Товар</param>
 /// <param name="sessionRows">Кол-во товара в рамках сессии</param>
 /// <param name="goodsTotal">Кол-во товаров в системе</param>
 private void CreateGood(GoodDto good, int sessionRows, int goodsTotal)
 {
     for (int i = 0; i < (sessionRows - goodsTotal); i++)
     {
         _context.Add(_mapper.Mapper.Map <GoodDto, Good>(good));
     }
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Order,CategoryId,BrandId,ImageUrl,Price,ProductionDate,Manufacturer,Name,Id")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brands, "Id", "Id", product.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            return(View(product));
        }
Ejemplo n.º 3
0
        public void ShouldAddACategoryWithContext()
        {
            var category = new ProductsCategory {
                Title = "Foo"
            };

            _db.Add(category);
            Assert.Equal(EntityState.Added, _db.Entry(category).State);
            Assert.True(category.Id < 0);
            Assert.Null(category.TimeStamp);
            _db.SaveChanges();
            Assert.Equal(EntityState.Unchanged, _db.Entry(category).State);
            Assert.Equal(0, category.Id);
            Assert.NotNull(category.TimeStamp);
            Assert.Equal(1, _db.ProductsCategories.Count());
        }
Ejemplo n.º 4
0
        public Users QueryUser(int subscriberId, string subscriberUniqueId, string userTeamSpeakClientUniqueId/*, string serverQueryUsername, string serverQueryPassword*/)
        {
            using (var db = new CoreContext())
            {
                var usersearch = db.Users.SingleOrDefault(x => x.UserTeamSpeakClientUniqueId == userTeamSpeakClientUniqueId && x.SubscriberUniqueId == subscriberUniqueId);

                if (usersearch != null)
                    return usersearch;

                Users newuser = new Users()
                {
                    SubscriberId = subscriberId,
                    SubscriberUniqueId = subscriberUniqueId,
                    UserTeamSpeakClientUniqueId = userTeamSpeakClientUniqueId,
                };                

                db.Add(newuser);
                db.SaveChanges();

                return newuser;
            }
        }
Ejemplo n.º 5
0
        protected override CommandResult <LoginShopOAuthReulst> OnExecute(object commandParameter)
        {
            var paramter = commandParameter as LoginShopOAuthParamter;
            var result   = new CommandResult <LoginShopOAuthReulst>
            {
                Data = new LoginShopOAuthReulst()
            };

            if (paramter == null)
            {
                return(ErrorResult <LoginShopOAuthReulst> .ParameterError);
            }

            try
            {
                string responseString = "";
                #region 获取用户信息
                string appid        = paramter.OAuthAppId;
                string appsecrect   = paramter.OAuthAppSecret;
                string interFaceUri = paramter.InterfaceUrl;
                string Key          = "Pub.GetMemberToken";
                var    param        = new
                {
                    AuthCode = paramter.MemberCode,
                    UserCode = appid
                };
                string data = $"key={ Key}&param={JsonConvert.SerializeObject(param)}&private={ appsecrect}";
                string sign = EncryptUtil.MD5Encrypt(data).ToLower();

                using (var http = new HttpClient(new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.GZip
                }))
                {
                    var paramdata = System.Web.HttpUtility.UrlEncode(JsonConvert.SerializeObject(param));

                    Serilog.Log.Logger.Information($"#{Key}input#{interFaceUri}?key={Key}&param={paramdata}&user={appid}&sign={sign}");
                    LogUtil.LogText("LoginShopOuathCommand", "Pub.GetMemberToken", $"#{Key}input#{interFaceUri}?key={Key}&param={paramdata}&user={appid}&sign={sign}");
                    http.DefaultRequestHeaders.CacheControl = new System.Net.Http.Headers.CacheControlHeaderValue()
                    {
                        NoCache = true
                    };

                    responseString = http.GetStringAsync($"{interFaceUri}?key={Key}&param={paramdata}&user={appid}&sign={sign}").Result;

                    LogUtil.LogText("LoginShopOuathCommand", "Pub.GetMemberToken", $"#{Key}output{responseString}");
                }
                #endregion

                //创建用户
                JObject resJobj = JsonConvert.DeserializeObject <JObject>(responseString);
                if (!resJobj["Error"].Value <bool>() && resJobj["Result"]["Token"] != null)
                {
                    string Token = resJobj["Result"]["Token"].Value <string>();
                    if (!string.IsNullOrEmpty(Token))
                    {
                        using (CoreContext context = new CoreContext())
                        {
                            MemberInfo _member = (from m in context.MemberInfo where m.ZlOpenId == Token select m).FirstOrDefault();
                            if (_member == null)
                            {
                                _member = new MemberInfo
                                {
                                    NickName     = resJobj["Result"]["Name"].Value <string>(),
                                    MemberName   = resJobj["Result"]["Name"].Value <string>(),
                                    PhotoUrl     = resJobj["Result"]["Photo"].Value <string>(),
                                    Sex          = resJobj["Result"]["Sex"].Value <string>(),
                                    ZlOpenId     = Token,
                                    AccountId    = Guid.NewGuid().ToString("N"),
                                    OwnerAccount = "admin",
                                    DeptCode     = "0001",
                                    AddDate      = DateTime.Now,
                                    LastLog      = DateTime.Now,
                                    LogTimes     = 1,
                                    Status       = "1"
                                };
                                context.MemberInfo.Add(_member);
                            }
                            var count = context.Database.ExecuteSqlCommand($"update member_ouath_code set status=-9 where member_account={_member.AccountId}");
                            var token = Guid.NewGuid().ToString("N");
                            context.Add(new MemberOuathCode()
                            {
                                MemberAccount = _member.AccountId,
                                OuathCode     = token,
                                CreateTime    = DateTime.Now,
                                Status        = 1
                            });
                            context.SaveChanges();
                            result.Data.Token = token;
                            //  Log.Information($"#LoginShopOuathCommand#OuathCode#{token}#MemberAccount#{_member.AccountId}");
                            LogUtil.LogText("LoginShopOuathCommand", "LoginShopOuathCommand", $"#OuathCode#{token}#MemberAccount#{_member.AccountId}");
                        }
                    }


                    //var identity = new ClaimsIdentity(MemberAuthorizeFilter.Scheme);
                    //identity.AddClaim(new Claim(ClaimTypes.Sid, _member.AccountId));
                    //HttpContext.SignInAsync(MemberAuthorizeFilter.Scheme, new ClaimsPrincipal(identity));
                    //return Redirect(WebUtility.UrlDecode(redirect));
                }
                else
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = responseString;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Logger.Error($"#{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType}#{ex.Message}");
                result.ErrorCode    = -1;
                result.ErrorMessage = ex.Message;
                return(result);
            }

            return(result);
        }
Ejemplo n.º 6
0
        protected override CommandResult <CreateBookOrderResult> OnExecute(object commandParameter)
        {
            var param  = commandParameter as CreateBookOrderParameter;
            var result = new CommandResult <CreateBookOrderResult>();

            result.Data = new CreateBookOrderResult();
            using (CoreContext context = new CoreContext())
            {
                var book = new BookUtil();
                if (book._Config == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }
                if (DateTime.Now < book._Config.StartTime)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动未开始";
                    return(result);
                }
                if (book._Config.EndTime < DateTime.Now)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }

                var pmodel = book._ProductConfig.Where(p => p.ProductNo == param.ProductNo).FirstOrDefault();
                if (pmodel == null)
                {
                    return(ErrorResult <CreateBookOrderResult> .ParameterError);
                }
                var pSku = pmodel.SkuList.Where(s => s.ProductSkuNo == param.ProductSkuNo).FirstOrDefault();
                if (pSku == null)
                {
                    return(ErrorResult <CreateBookOrderResult> .ParameterError);
                }

                PaymentConfig payment = (from p in context.PaymentConfig where p.Id == param.PayId select p).FirstOrDefault();

                if (payment == null)
                {
                    result.ErrorMessage = "请设置支付方式";
                    result.ErrorCode    = -1;
                    return(result);
                }

                var redisdb    = RedisClient.GetDatabase();
                var orderIndex = redisdb.HashIncrementAsync("zlan.membercart.index", "OrderIndex").Result;

                string mainNo = string.Format("{0:yyMMddHHmmss}{1:D6}", DateTime.Now, orderIndex);
                //订单号
                string orderNo = string.Format("AT{0}00", mainNo);

                decimal totalFee = 0, discountFee = 0, productFee = 0;
                productFee = pSku.SalePrice;

                //开启事务
                using (var tran = context.Database.BeginTransaction())
                {
                    try
                    {
                        totalFee = productFee - discountFee;
                        //金额小于等于0创建失败
                        if (totalFee <= 0)
                        {
                            return(ErrorResult <CreateBookOrderResult> .ParameterError);
                        }
                        var order = new PayOrder()
                        {
                            OrderNo       = orderNo,
                            PaymentId     = param.PayId,
                            PayFee        = totalFee,
                            MemberAccount = param.MemberAccount,
                            TotalFee      = totalFee,
                            CreateTime    = DateTime.Now,
                            Kind          = "gift",
                            Status        = 0,
                            ProductFee    = productFee,
                            DiscountFee   = discountFee,
                            Memo          = $"【{pmodel.ProductName}】预付订单"
                        };
                        context.Add(order);

                        var bookinfo = new BookInfo()
                        {
                            Address       = param.Address,
                            City          = param.City,
                            Province      = param.Province,
                            Area          = param.Araea,
                            Phone         = param.Phone,
                            Name          = param.Name,
                            Counter       = 1,
                            ProductNo     = pmodel.ProductNo,
                            ProductSkuNo  = pSku.ProductSkuNo,
                            Status        = 0,
                            OrderNo       = orderNo,
                            ConfigId      = 1,
                            ProductConfig = JsonConvert.SerializeObject(pmodel),
                            StartTime     = book._ValidDate["Start"].Value <DateTime>(),
                            EndTime       = book._ValidDate["End"].Value <DateTime>(),
                            MemberAccount = param.MemberAccount,
                            CouponId      = pmodel.CouponId,
                            AddressId     = param.AddressId == 0 ? param.AddressId = -99 : param.AddressId
                        };
                        context.Add(bookinfo);
                        context.SaveChanges();

                        result.Data.PayId = payment.Id;
                        result.Data.PayNo = orderNo;
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        result = ErrorResult <CreateBookOrderResult> .ParameterError;
                        result.ErrorMessage = ex.Message;
                        return(result);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
 public void Add(T entity)
 {
     _context.Add(entity);
 }