Пример #1
0
 public JsonResult AddDianpu(AddDianpuPostModel model)
 {
     var result = new AddDianpuPostResult();
     using (var db = DbContextFactory.CreateDbContext())
     {
         Xiake xiake;
         TokenXCodeValidation.Validate(model, db, out xiake);
         var dianpu = new Dianpu()
         {
             JianghuType = model.Jianghutype, 
             Url = model.Url,
             Name = model.Name, 
             Zhanggui = xiake,
             CreateTime = DateTime.Now
         };
         db.Dianpus.Add(dianpu);
         db.SaveChanges();
         result.ID = dianpu.Id;
     }
     return new JsonResult() { Data = result };
 }
Пример #2
0
       public  long  AddDianpu(BangpaiType bangpaiType,   string url, string name  )
        { 
            using (var db = DbContextFactory.CreateDbContext())
            {
                Xiake xiake = db.Xiakes.FirstOrDefault(a => a.XiakeName == Thread.CurrentPrincipal.Identity.Name);
                if(xiake.UserType != XiakeType.Zhanggui)
                    throw new FaultException("非掌柜身份不可以建立店铺!");
                var dianpus = db.Dianpus.Where(a => a.Zhanggui.Id == xiake.Id).ToArray();
                if(dianpus.Any(a=>a.Url == url))
                    throw new FaultException("已存在相同网址的店铺");
                if(dianpus.Any(a=>a.Bangpai == bangpaiType && a.Name == name))
                    throw new FaultException("已存在相同用户名的同类店铺");

                var dianpu = new Dianpu()
                {
                    Bangpai = bangpaiType, 
                    Url = url,
                    Name = name, 
                    Zhanggui = xiake
                };
                db.Dianpus.Add(dianpu);
                db.SaveChanges();
                return dianpu.Id;
            }
        }