public ActionResult Create(CollocationDto coldto, Administrator admidto) { Collocation coll = AutoMapper.Mapper.Map <Collocation>(coldto); coll.Numb = admidto.Member.UniquelyIdentifies; coll.IsDeleted = false; coll.IsEnabled = true; var admin = _administratContract.Administrators.Where(c => c.IsDeleted == false && c.IsEnabled == true && c.MemberId == admidto.MemberId).FirstOrDefault(); if (admin != null) { coll.AdminiId = admin.Id; } else { Administrator adm = AutoMapper.Mapper.Map <Administrator>(admidto); adm.Member = _memberContract.Members.FirstOrDefault(c => c.Id == adm.MemberId); adm.IsLogin = true; adm.IsDeleted = false; adm.IsEnabled = true; adm.JobPositionId = 1; coll.Admini = adm; } var result = _collocationContract.Insert(coll); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult AddCollocation(string collocationjson) { var data = Newtonsoft.Json.JsonConvert.DeserializeObject <CollocationDataModel>(collocationjson); if (data == null) { throw new HimallException("添加组合购参数错误!"); } if (data.Title.Trim().Length <= 0) { throw new HimallException("组合购的标题不能为空!"); } if (data.ShortDesc.Length >= 500) { throw new HimallException("组合描述不能超过500字!"); } var model = new Collocation { Id = data.Id, ShopId = CurrentSellerManager.ShopId, Title = data.Title, StartTime = data.StartTime, EndTime = data.EndTime, ShortDesc = data.ShortDesc, Products = data.CollocationPoruducts.Select(a => new CollocationProduct { Id = a.Id, DisplaySequence = a.DisplaySequence, IsMain = a.IsMain, ProductId = a.ProductId, SKUs = a.CollocationSkus.Select(b => new CollocationSKU() { Id = b.Id, Price = b.Price, SKUId = b.SkuID, SKUPrice = b.SkuPirce, }).ToList() }).ToList() }; try { _iCollocationService.AddCollocation(model); return(Json(new Result() { success = true, msg = "添加成功!" })); } catch (Exception ex) { return(Json(new Result { msg = ex.Message, success = false })); } }
public void AddCollocation(Collocation info) { CheckCollocationDate(info.ShopId, info.EndTime); var date = DateTime.Now.Date; var mainId = info.Products.Where(a => a.IsMain == true).Select(a => a.ProductId).FirstOrDefault(); var flag = DbFactory.Default .Get <CollocationPoruductInfo>() .InnerJoin <CollocationInfo>((cpi, ci) => ci.Id == cpi.ColloId) .Where(a => a.IsMain == true && a.ProductId == mainId) .Where <CollocationInfo>(a => a.EndTime > date) .Exist(); if (flag) { throw new MallException("此主商品已存在组合购,请勿重复添加!"); } DbFactory.Default .InTransaction(() => { var model = new CollocationInfo { Title = info.Title, StartTime = info.StartTime, EndTime = info.EndTime, ShortDesc = info.ShortDesc, ShopId = info.ShopId, CreateTime = DateTime.Now }; var ret1 = DbFactory.Default.Add(model); var products = info.Products.Select(p => new CollocationPoruductInfo { ColloId = model.Id, ProductId = p.ProductId, DisplaySequence = p.DisplaySequence, IsMain = p.IsMain }).ToList(); var ret2 = DbFactory.Default.AddRange(products); var skus = info.Products.SelectMany(p => { var pro = products.FirstOrDefault(o => o.ProductId == p.ProductId); return(p.SKUs.Select(s => new CollocationSkuInfo { ColloProductId = pro.Id, Price = s.Price, ProductId = p.ProductId, SkuID = s.SKUId, SkuPirce = s.SKUPrice, })); }); var ret3 = DbFactory.Default.Add(skus); }); }
public void EditCollocation(Collocation model) { CheckCollocationDate(model.ShopId, model.EndTime); var coll = DbFactory.Default.Get <CollocationInfo>().Where(p => p.Id == model.Id).FirstOrDefault(); if (coll.EndTime < DateTime.Now.Date) { throw new MallException("该活动已结束,无法修改!"); } DbFactory.Default .InTransaction(() => { //修改基本信息 DbFactory.Default.Set <CollocationInfo>() .Set(p => p.Title, model.Title) .Set(p => p.StartTime, model.StartTime) .Set(p => p.EndTime, model.EndTime) .Set(p => p.ShortDesc, model.ShortDesc) .Where(p => p.Id == model.Id) .Succeed(); var products = model.Products.Select(p => new CollocationPoruductInfo { ColloId = model.Id, ProductId = p.ProductId, DisplaySequence = p.DisplaySequence, IsMain = p.IsMain }).ToList(); var delProducts = DbFactory.Default.Get <CollocationPoruductInfo>(p => p.ColloId == model.Id).Select(p => p.Id).ToList <long>(); DbFactory.Default.Del <CollocationPoruductInfo>(p => p.ColloId == model.Id); DbFactory.Default.AddRange(products); var skus = model.Products.SelectMany(p => { var pro = products.FirstOrDefault(o => o.ProductId == p.ProductId); return(p.SKUs.Select(s => new CollocationSkuInfo { ColloProductId = pro.Id, Price = s.Price, ProductId = p.ProductId, SkuID = s.SKUId, SkuPirce = s.SKUPrice, })); }); DbFactory.Default.Del <CollocationSkuInfo>(p => p.ColloProductId.ExIn(delProducts)); DbFactory.Default.AddRange(skus); }); }
public ActionResult Update(Collocation colldto) { OperationResult resul = new OperationResult(OperationResultType.Error); var origpass = Request["origPass"]; Administrator admin = _administratContract.Administrators.Where(c => c.IsDeleted == false && c.IsEnabled == true && c.Id == colldto.Admini.Id).FirstOrDefault(); Collocation coll = _collocationContract.Collocations.Where(c => c.IsDeleted == false && c.IsEnabled == true && c.Numb == colldto.Admini.Member.UniquelyIdentifies).FirstOrDefault(); if (admin != null && coll != null) { if (!string.IsNullOrEmpty(origpass)) { origpass = origpass.MD5Hash(); if (admin.Member.MemberPass == origpass) { admin.Member.MemberPass = colldto.Admini.Member.MemberPass.MD5Hash(); } else { resul = new OperationResult(OperationResultType.Error, "原密码不正确"); } } admin.Member = Utils.UpdateNavMemberInfo(colldto.Admini, _memberContract); var cId = coll.Id; coll = AutoMapper.Mapper.Map(colldto, coll); coll.Id = cId; coll.Admini = admin; coll.AdminiId = admin.Id; coll.Numb = admin.Member.UniquelyIdentifies; resul = _collocationContract.Update(coll); } else { resul = new OperationResult(OperationResultType.Error, "指定的修改对象不存在"); } return(Json(resul, JsonRequestBehavior.AllowGet)); }
private void button2_Click(object sender, EventArgs e) { listBoxInArticle.Items.Clear(); listBoxLExi.Items.Clear(); listBoxNonLexi.Items.Clear(); listBoxSemiLexi.Items.Clear(); try { string text = richTextBox1.Text; text = Utilities.ClearCharacter(text);// karakterleri temizler text = text.Trim(); string[] array = text.Split(' ');//bütün yazıyı boşluklara göre ayırıp bir diziye dolduruyor string[] array2 = new String[array.Length]; for (int i = 0; i < array.Length; i++) { if (array[i].Trim() != "") { array2[i] = array[i]; } } Collocation c = new Collocation(); for (int i = 0; i < array.Length - 3; i++) { string value1 = array[i].ToString().Trim() + " " + array[i + 1].ToString().Trim(); string value2 = array[i].ToString().Trim() + " " + array[i + 1].ToString().Trim() + " " + array[i + 2].ToString().Trim(); string value3 = array[i].ToString().Trim() + " " + array[i + 1].ToString().Trim() + " " + array[i + 2].ToString().Trim() + " " + array[i + 3].ToString().Trim(); if (!String.IsNullOrEmpty(value1)) { //foreach (var val in listBoxOurList.Items) //{ // if (val.ToString().Trim().ToLower() == value1.Trim().ToLower()) // { // //listBoxInArticle.Items.Add(value1); // ////if (value1.Trim() != "") // //// c = db.Collocation.Where(x => x.CollocationName == value1).FirstOrDefault();//veri tabanından bulunan ikilemeyi çeker ve grubunu tespit için gerekli // //if (c.Type == 1)//Lexicalized // // listBoxLExi.Items.Add(value1); // //if (c.Type == 2)//Semi-lexicalized // // listBoxSEmiLexi.Items.Add(value1); // //if (c.Type == 3)//Non-lexicalized // // listBoxNonLexi.Items.Add(value1); // } // else if (val.ToString().Trim().ToLower() == value2.Trim().ToLower()) // { // listBoxInArticle.Items.Add(value2); // if (value2.Trim() != "") // c = db.Collocation.Where(x => x.CollocationName == value2).FirstOrDefault(); // if (c.Type == 1) // listBoxLExi.Items.Add(value2); // if (c.Type == 2) // listBoxSEmiLexi.Items.Add(value2); // if (c.Type == 3) // listBoxNonLexi.Items.Add(value2); // } // else if (val.ToString().Trim().ToLower() == value3.Trim().ToLower()) // { // listBoxInArticle.Items.Add(value3); // if (value3.Trim() != "") // c = db.Collocation.Where(x => x.CollocationName == value3).FirstOrDefault(); // if (c.Type == 1) // listBoxSEmiLexi.Items.Add(value2); // if (c.Type == 2) // listBoxSEmiLexi.Items.Add(value2); // if (c.Type == 3) // listBoxSEmiLexi.Items.Add(value2); // } //} } } string last2Value = array[array.Length - 2] + " " + array[array.Length - 1]; string last3value = array[array.Length - 3] + " " + array[array.Length - 2] + " " + array[array.Length - 1]; foreach (var val in listBoxOurList.Items) { if (val.ToString().Trim().ToLower() == last2Value.Trim().ToLower()) { if (last2Value.Trim() != "") { c = db.Collocation.Where(x => x.CollocationName == last2Value).FirstOrDefault(); } listBoxInArticle.Items.Add(last2Value); if (c.Type == 1) { listBoxLExi.Items.Add(last2Value); } if (c.Type == 2) { listBoxSemiLexi.Items.Add(last2Value); } if (c.Type == 3) { listBoxNonLexi.Items.Add(last2Value); } } } foreach (var val in listBoxOurList.Items) { if (val.ToString().Trim().ToLower() == last3value.Trim().ToLower()) { if (last3value.Trim() != "") { c = db.Collocation.Where(x => x.CollocationName == last3value).FirstOrDefault(); } listBoxInArticle.Items.Add(last2Value); if (c.Type == 1) { listBoxLExi.Items.Add(last3value); } if (c.Type == 2) { listBoxSemiLexi.Items.Add(last3value); } if (c.Type == 3) { listBoxNonLexi.Items.Add(last3value); } } } listBoxNonLexi.Items.Add(listBoxNonLexi.Items.Count); } catch (Exception ex) { MessageBox.Show("Unexpected problem! " + ex.Message); } label1.Text = listBoxInArticle.Items.Count.ToString(); //buttonAnalysis.PerformClick(); }