Пример #1
0
        public Marketing_Activities CreateNewActivity(Marketing_Activities activity)
        {
            if(activity==null)
            {
                throw new KMBitException("参数输入错误");
            }
            if(activity.AgentId!=CurrentLoginUser.User.Id)
            {
                throw new KMBitException("代理商用户不能为别的代理商用户的客户创建活动");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Customer customer = (from c in db.Customer where c.Id == activity.CustomerId select c).FirstOrDefault<Customer>();
                if(customer==null)
                {
                    throw new KMBitException(string.Format("编号为:{0}的客户不存在",activity.CustomerId));
                }

                db.Marketing_Activities.Add(activity);
                db.SaveChanges();
            }

            return activity;
        }
Пример #2
0
        public bool UpdateActivity(Marketing_Activities activity)
        {
            bool result = false;
            if (activity == null || activity.Id <= 0)
            {
                throw new KMBitException("参数错误");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Marketing_Activities dbac = (from a in db.Marketing_Activities where a.Id == activity.Id select a).FirstOrDefault<Marketing_Activities>();
                if (dbac == null)
                {
                    throw new KMBitException("参数错误");
                }

                if (!string.IsNullOrEmpty(activity.Name))
                {
                    dbac.Name = activity.Name;
                }
                if (!string.IsNullOrEmpty(activity.Description))
                {
                    dbac.Description = activity.Description;
                }

                dbac.Enabled = activity.Enabled;
                db.SaveChanges();
                result = true;
            }

            return result;
        }
Пример #3
0
        public ActionResult CreateCustomerActivity(CustomerActivityModel model)
        {            
            if(ModelState.IsValid)
            {
                ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
                Marketing_Activities activity = new Marketing_Activities()
                {
                    AgentId = User.Identity.GetUserId<int>(),
                    CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                    CustomerId = model.CustomerId,
                    Description = model.Description,
                    ScanType = model.ScanType,
                    Enabled = model.Enable,
                    Name = model.Name,
                    Id=model.Id
                };

                if (model.Id==0)
                {                   
                    activity = activityMgr.CreateNewActivity(activity);
                    if (activity.Id > 0)
                    {
                        return Redirect("/Agent/CustomerAcivities?customerId=" + model.CustomerId);
                    }
                }else
                {
                    activityMgr.UpdateActivity(activity);
                    return Redirect("/Agent/CustomerAcivities?customerId=" + model.CustomerId);
                } 
            }
            List<DictionaryTemplate> scanTypes = StaticDictionary.GetScanTypeList();
            ViewBag.ScanTypes = new SelectList(from st in scanTypes select new { Id = st.Id, Name = st.Value }, "Id", "Name");
            return View(model);
        }