//取店长时从用户users表里查创建人是当前账号,并且关联角色类型为1(商户),角色为店长的用户 // GET: merchants/ShowInvest ok public ActionResult SetShopowner(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //有问题 var mer = db.merchants.Find(id); var sshop = new SetShopper { id = (long)id, code = (from s in db.shops where s.id == mer.shop_id select s.code).FirstOrDefault(), gourmetplaceName = (from g in db.gourmet_palaces where g.id == mer.gourmet_palace_id select g.name).FirstOrDefault() }; ViewData["code"] = sshop.code; ViewData["gourmetplaceName"] = sshop.gourmetplaceName; ViewData["merchantid"] = sshop.id; return(View("SetShopowner", sshop)); }
public ActionResult SaveShopowner(SetShopper shop, string gourmetplaceName, string code, long ListName) { //当前的商户 long merchantid = (from p in db.merchants where (p.name == Session["sesMerchantName"]) select p.id).First(); var gourmentplaceid = (from p in db.gourmet_palaces where (p.name == gourmetplaceName) select p.id).FirstOrDefault(); var shid = (from p in db.shops where (p.code == code) select p.id).FirstOrDefault(); //var userid = (from p in db.users where (p.id == (long)ListName) select p.id).FirstOrDefault(); var userid = ListName; var mer = (from m in db.merchants where (m.id == merchantid) select m).FirstOrDefault(); mer.gourmet_palace_id = (int)gourmentplaceid; mer.shop_id = (int)shid; mer.shopowner = (int)userid; db.Entry(mer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); // RedirectToAction("Index"); return(View("Index", getMerchantcost())); }