コード例 #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 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);
 }
コード例 #3
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);
 }
コード例 #4
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
        public ActionResult UpdateResource(ResourceModel model)
        {
            resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
            List<KMBit.DAL.Area> provinces = null;
            List<KMBit.DAL.Sp> sps = null;
            if (ModelState.IsValid)
            {
                DAL.Resource resource = null;
                if (model.Id > 0)
                {
                    List<BResource> resources = resourceMgt.FindResources((int)model.Id, null, 0, out total);
                    if (resources == null)
                    {
                        ViewBag.Message = "试图编辑的资源不存在";
                        return View("Error");
                    }
                    BResource bresouce = resources[0];
                    resource = bresouce.Resource;
                }
                else
                {
                    resource = new DAL.Resource();
                    resource.Name = model.Name;
                    resource.CreatedBy = User.Identity.GetUserId<int>();
                    resource.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }

                resource.Address = model.Address;
                resource.City_Id = model.City;
                resource.Contact = model.Contact;
                resource.Description = model.Description;
                resource.Email = model.Email;
                resource.Enabled = model.Enabled;
                resource.Province_Id = model.Province;
                resource.SP_Id = model.SP;
                resource.UpdatedBy = User.Identity.GetUserId<int>();
                resource.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);

                try
                {
                    bool result = false;
                    if (resource.Id <= 0)
                    {
                        result = resourceMgt.CreateResource(resource);
                    } else
                    {
                        result = resourceMgt.UpdateResource(resource);
                    }
                    if (result)
                    {
                        return RedirectToAction("Resources");
                    }

                }
                catch (KMBitException ex)
                {
                    ViewBag.Exception = ex;
                }
                catch (Exception nex)
                {
                    ViewBag.ErrMsg = nex.Message;
                }
                finally
                {
                }
            }
            else
            {
                string validationErrors = string.Join(",",
                    ModelState.Values.Where(E => E.Errors.Count > 0)
                    .SelectMany(E => E.Errors)
                    .Select(E => E.ErrorMessage)
                    .ToArray());

                ViewBag.ErrMsg = validationErrors;
            }

            provinces = resourceMgt.GetAreas(0);
            sps = resourceMgt.GetSps();
            ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
            ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province), "Id", "Name");
            ViewBag.SPs = new SelectList(sps, "Id", "Name");
            return View("CreateResource",model);
        }
コード例 #5
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
        public ActionResult EditResource(int resourceId)
        {
            resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
            if (resourceId <= 0)
            {
                ViewBag.Message = "资源编号不正确";
                return View("Error");
            }
            List<BResource> resources = resourceMgt.FindResources(resourceId, null, 0,out total);
            if (resources == null)
            {
                ViewBag.Message = "试图编辑的资源不存在";
                return View("Error");
            }

            BResource resouce = resources[0];
            ResourceModel model = new ResourceModel()
            {
                Address = resouce.Resource.Address,
                City = (int)resouce.Resource.City_Id,
                Contact = resouce.Resource.Contact,
                Description = resouce.Resource.Description,
                Email = resouce.Resource.Email,
                Enabled = resouce.Resource.Enabled,
                Id = resouce.Resource.Id,
                Name = resouce.Resource.Name,
                Province = resouce.Resource.Province_Id,
                SP = resouce.Resource.SP_Id
            };
            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(resourceMgt.GetAreas(model.Province), "Id", "Name");
            ViewBag.SPs = new SelectList(sps, "Id", "Name");
            return View("CreateResource", model);
        }
コード例 #6
0
ファイル: AdminController.cs プロジェクト: Bobom/kuanmai
 public ActionResult CreateResource()
 {
     resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
     List<KMBit.DAL.Area> provinces = resourceMgt.GetAreas(0);
     List<KMBit.DAL.Sp> sps = resourceMgt.GetSps();
     //List<SelectListItem> selProvinces = (from p in provinces select new SelectListItem { Text=p.Name,Value=p.Id.ToString() }).ToList<SelectListItem>();            
     ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
     ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     ViewBag.SPs = new SelectList(sps, "Id", "Name");
     ResourceModel model = new ResourceModel() { Enabled = true, Id = 0 };
     return View("CreateResource", model);
 }