|
@@ -32,21 +32,47 @@ namespace MySystem
|
|
|
int UserId = int.Parse(json["UserId"].ToString());
|
|
int UserId = int.Parse(json["UserId"].ToString());
|
|
|
int BrandId = int.Parse(json["BrandId"].ToString());
|
|
int BrandId = int.Parse(json["BrandId"].ToString());
|
|
|
WebCMSEntities dbnew = new WebCMSEntities();
|
|
WebCMSEntities dbnew = new WebCMSEntities();
|
|
|
- string IdBrand = UserId + "_" + BrandId;
|
|
|
|
|
- UserMachineData machineData = dbnew.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
|
|
- if (machineData == null)
|
|
|
|
|
|
|
+ string IdBrand = "";
|
|
|
|
|
+ if (BrandId == 0)
|
|
|
{
|
|
{
|
|
|
- machineData = dbnew.UserMachineData.Add(new UserMachineData()
|
|
|
|
|
|
|
+ var Brands = dbnew.KqProducts.Where(m => m.Status == 1).ToList();
|
|
|
|
|
+ foreach (var Brand in Brands)
|
|
|
{
|
|
{
|
|
|
- IdBrand = IdBrand
|
|
|
|
|
- }).Entity;
|
|
|
|
|
|
|
+ IdBrand = UserId + "_" + Brand.Id;
|
|
|
|
|
+ UserMachineData machineData = dbnew.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
|
|
+ if (machineData == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ machineData = dbnew.UserMachineData.Add(new UserMachineData()
|
|
|
|
|
+ {
|
|
|
|
|
+ IdBrand = IdBrand
|
|
|
|
|
+ }).Entity;
|
|
|
|
|
+ dbnew.SaveChanges();
|
|
|
|
|
+ }
|
|
|
|
|
+ machineData.BindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 1);
|
|
|
|
|
+ machineData.UnBindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0);
|
|
|
|
|
+ machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
|
|
|
|
|
+ dbnew.SaveChanges();
|
|
|
|
|
+ dbnew.Dispose();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ IdBrand = UserId + "_" + BrandId;
|
|
|
|
|
+ UserMachineData machineData = dbnew.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
|
|
+ if (machineData == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ machineData = dbnew.UserMachineData.Add(new UserMachineData()
|
|
|
|
|
+ {
|
|
|
|
|
+ IdBrand = IdBrand
|
|
|
|
|
+ }).Entity;
|
|
|
|
|
+ dbnew.SaveChanges();
|
|
|
|
|
+ }
|
|
|
|
|
+ machineData.BindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 1);
|
|
|
|
|
+ machineData.UnBindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0);
|
|
|
|
|
+ machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
|
|
|
dbnew.SaveChanges();
|
|
dbnew.SaveChanges();
|
|
|
|
|
+ dbnew.Dispose();
|
|
|
}
|
|
}
|
|
|
- machineData.BindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 1);
|
|
|
|
|
- machineData.UnBindCount = dbnew.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0);
|
|
|
|
|
- machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
|
|
|
|
|
- dbnew.SaveChanges();
|
|
|
|
|
- dbnew.Dispose();
|
|
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|