コード例 #1
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
        public ActionResult UpdateResourceTaocan(ResourceTaocanModel model)
        {
            bool ret = false;
            resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
            List<BResource> resources = resourceMgt.FindResources(model.ResoucedId, null, 0, out total);
            if (resources == null || resources.Count == 0)
            {
                ViewBag.Message = "资源信息丢失";
                return View("Error");
            }
            BResource resource = resources[0];

            if (ModelState.IsValid)
            {
                KMBit.DAL.Resource_taocan taocan = null;
                if(model.Id>0)
                {
                    int total = 0;
                    List<BResourceTaocan> ts = resourceMgt.FindResourceTaocans(model.Id, 0, 0, out total);
                    if (total == 1)
                    {
                        taocan = ts[0].Taocan;
                    }
                }else
                {
                    taocan = new DAL.Resource_taocan();
                    taocan.CreatedBy = User.Identity.GetUserId<int>();
                    taocan.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    taocan.Quantity = model.Quantity;
                    taocan.Resource_id = model.ResoucedId;
                }
                taocan.Serial = model.Serial;
                taocan.Area_id = model.Province != null ? (int)model.Province : 0;
                taocan.City_id = model.City!=null ?(int)model.City:0;
                taocan.NumberProvinceId = model.NumberProvince != null ? (int)model.NumberProvince : 0;
                taocan.NumberCityId = model.NumberCity != null ? (int)model.NumberCity : 0;
                taocan.Enabled = model.Enabled;
                taocan.Purchase_price = model.PurchasePrice;
                taocan.EnableDiscount = model.EnabledDiscount;
                taocan.Resource_Discount = model.Discount;
                taocan.Sale_price = model.SalePrice;
                taocan.Sp_id = model.SP != null ? (int)model.SP : 0;               
                taocan.UpdatedBy = User.Identity.GetUserId<int>();
                taocan.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                try
                {
                    if (model.Id <= 0)
                    {
                        ret = resourceMgt.CreateResourceTaocan(taocan);
                    }
                    else
                    {
                        ret = resourceMgt.UpdateResourceTaocan(taocan);
                    }
                }
                catch(KMBitException kex)
                {
                    KMLogger.GetLogger().Error(kex);
                    ViewBag.Message = kex.Message;
                    return View("Error");
                }                
                catch(Exception ex)
                {
                    KMLogger.GetLogger().Fatal(ex);
                    ViewBag.Message = "未知错误,请联系系统管理员";
                    return View("Error");
                }
                if (ret)
                {
                    return Redirect("/Admin/ViewResourceTaoCan?resourceId=" + model.ResoucedId);
                }
                else
                {
                    ViewBag.Message = "未知错误,请联系系统管理员";
                    return View("Error");
                }
            }else
            {
                var errors = ModelState
                .Where(x => x.Value.Errors.Count > 0)
                .Select(x => new { x.Key, x.Value.Errors })
                .ToArray();
                ViewBag.Message = "资源套餐创建失败";
                return View("Error");
            }
            List<KMBit.DAL.Area> provinces = null;
            List<KMBit.DAL.Sp> sps = null;
            provinces = resourceMgt.GetAreas(0);
            sps = resourceMgt.GetSps();
            ViewBag.Resource = resource;
            ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
            ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province != null ? (int)model.Province : 0), "Id", "Name");
            ViewBag.SPs = new SelectList(sps, "Id", "Name");

            return View("CreateResourceTaocan",model);
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
 public ActionResult CreateResourceTaocan(ResourceTaocanModel model)
 {
     bool state = ModelState.IsValid;
     return UpdateResourceTaocan(model);
 }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
 public ActionResult UpdateResourceTaocan(int taocanId)
 {           
     if(taocanId<=0)
     {
         ViewBag.Message = "套餐信息丢失";
         return View("Error");
     }
     resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
     List<BResourceTaocan> resourceTaocans = resourceMgt.FindResourceTaocans(taocanId, 0, 0, out total, 1, 1);
     if(total==0)
     {
         ViewBag.Message = "编号为"+taocanId+"的套餐不存在";
         return View("Error");
     }
     BResourceTaocan bTaocan = resourceTaocans[0];
     ResourceTaocanModel model = new ResourceTaocanModel()
     {
         Id = bTaocan.Taocan.Id,
         Serial = bTaocan.Taocan.Serial,
         Province = bTaocan.Taocan.Area_id,
         City = bTaocan.Taocan.City_id,
         NumberProvince=bTaocan.Taocan.NumberProvinceId,
         NumberCity=bTaocan.Taocan.NumberCityId,
         Enabled = bTaocan.Taocan.Enabled,
         PurchasePrice = bTaocan.Taocan.Purchase_price,
         Quantity = bTaocan.Taocan.Quantity,
         ResoucedId = bTaocan.Taocan.Resource_id,
         SalePrice = bTaocan.Taocan.Sale_price,
         SP = bTaocan.Taocan.Sp_id,
         Discount = bTaocan.Taocan.Resource_Discount,
         EnabledDiscount = bTaocan.Taocan.EnableDiscount,
         
     };
   
     List<KMBit.DAL.Area> provinces = null;
     List<KMBit.DAL.Sp> sps = null;
     provinces = resourceMgt.GetAreas(0);
     sps = resourceMgt.GetSps();
     ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
     if (model.City > 0)
     {
         ViewBag.Cities = new SelectList(resourceMgt.GetAreas((int)model.Province), "Id", "Name");
     }
     else
     {
         ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     }
     if(model.NumberCity>0)
     {
         ViewBag.NCities = new SelectList(resourceMgt.GetAreas((int)model.NumberProvince), "Id", "Name");
     }else
     {
         ViewBag.NCities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     }
     ViewBag.SPs = new SelectList(sps, "Id", "Name");
     ViewBag.Resource = bTaocan.Resource;
     return View("CreateResourceTaocan",model);
 }
コード例 #4
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
 public ActionResult CreateResourceTaocan(int? resourceId)
 {
     if(resourceId==null)
     {
         ViewBag.Message = "资源信息丢失";
         return View("Error");
     }
     int id = (int)resourceId;            
     ResourceTaocanModel mode = new ResourceTaocanModel() { ResoucedId=id,EnabledDiscount=true}; 
     if (id <= 0)
     {
         ViewBag.Message = "资源信息丢失";
         return View("Error");
     }
     resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());            
     List<BResource> resources = resourceMgt.FindResources(id, null, 0, out total);
     if(resources == null || resources.Count==0)
     {
         ViewBag.Message = "资源信息丢失";
         return View("Error");
     }
     BResource resource = resources[0];
     List<KMBit.DAL.Area> provinces = null;
     List<KMBit.DAL.Sp> sps = null;
     provinces = resourceMgt.GetAreas(0);
     sps = resourceMgt.GetSps();
     ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
     ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     ViewBag.NCities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     ViewBag.SPs = new SelectList(sps, "Id", "Name");
     ViewBag.Resource = resource;
     mode.Enabled = true;
     mode.EnabledDiscount = true;          
     return View(mode);
 }