public async Task <IHttpActionResult> Delete(int id) { try { var currentUser = await GetCurrentUser(); PlanBLL bll = new PlanBLL(_unit); bool isAdmin = await AppUserManager.IsInRoleAsync(currentUser.Id, "Admin"); if (isAdmin) { bll.Delete(id); } else { var w = bll.GetByID(id); if (w.Owner == currentUser.Id) { bll.Delete(id); } else { BadRequest("You don't have permission to delete this plan."); } } } catch (Exception ex) { LogHelper.Error(_log, ex.ToString()); return(InternalServerError(ex)); } return(Ok()); }
public void Test_Create() { PlanBLL bll = new PlanBLL(_unit); Plan b = new Plan { Owner = "2b658482-6a38-4ed3-b356-77fe9b1569f1", Content = "test content", TradingDate = 20160816, Status = "Open", Created = DateTime.Now, Modified = DateTime.Now }; bll.Create(b); b = new Plan { Owner = "2b658482-6a38-4ed3-b356-77fe9b1569f1", Content = "test content222", TradingDate = 20160817, ZoneId = 2, Status = "Open", Created = DateTime.Now, Modified = DateTime.Now }; bll.Create(b); }
public ActionResult Edit(int id) { ViewBag.listPrizeType = Common.EnumToSelectListItem(typeof(SysEnum.PrizeType)); PlanInfo info = PlanBLL.GetList(p => p.ID == id).FirstOrDefault(); return(View(info)); }
public ActionResult Index(int page = 1) { var list = PlanBLL.GetList(p => true); list = list.OrderBy(a => a.AgenterName).ThenBy(a => a.DateBegin).ThenBy(a => a.SortID); IPagedList <PlanInfo> result = list.ToPagedList(page, 50); return(View(result)); }
public Cli() { clientBLL = new ClientBLL(); historyBLL = new HistoryBLL(); optionBLL = new OptionBLL(); planBLL = new PlanBLL(); subOptionBLL = new SubOptionBLL(); subscriptionBLL = new SubscriptionBLL(); }
public ActionResult Create(PlanInfo info) { info.Enable = true; PlanBLL.Create(info); if (info.ID > 0) { return(Json(new APIJson(0, "添加成功"))); } return(Json(new APIJson(-1, "添加失败"))); }
public void Test_GetListByZone() { PlanBLL bll = new PlanBLL(_unit); string owner = "2b658482-6a38-4ed3-b356-77fe9b1569f1"; int? zoneId = 2; var jList = bll.GetListByZone(owner, null); jList = bll.GetListByZone(owner, zoneId); }
public ActionResult Delete(int id) { PlanInfo info = PlanBLL.GetList(p => p.ID == id).FirstOrDefault(); if (null == info) { return(Json(new APIJson(-1, "删除失败,参数有误", info))); } if (PlanBLL.Delete(info)) { return(Json(new APIJson(0, "删除成功", info))); } return(Json(new APIJson(-1, "删除失败,请重试", info))); }
public void GetPlanList(DateTime sTime, DateTime eTime, string routeID, string areaID, string deviceID) { string idkey = Request.Cookies["ID_KEY"].Value.ToString(); //string userID = "zhangsan"; string userID = bl.GetUserNameById(idkey, out errMsg); PlanBLL plan = new PlanBLL(); int page = Convert.ToInt32(Request["page"].ToString()); int rows = Convert.ToInt32(Request["rows"].ToString()); //DataTable dt = plan.GetPlan("zhangsan", routeID, areaID, deviceID, sTime, eTime, (page - 1) * rows + 1, page * rows); //count = plan.GetPlanCount("zhangsan", routeID, areaID, deviceID, sTime, eTime); DataTable dt = plan.GetPlan(userID, routeID, areaID, deviceID, sTime, eTime, (page - 1) * rows + 1, page * rows); count = plan.GetPlanCount(userID, routeID, areaID, deviceID, sTime, eTime); IList <Hashtable> list = new List <Hashtable>(); foreach (DataRow item in dt.Rows) { Hashtable ht = new Hashtable(); string startTime = item["sTime"].ToString(); string endTime = item["eTIme"].ToString(); string cTime = item["cTime"].ToString(); string uTime = item["uTime"].ToString(); ht.Add("ID", item["ID"]); ht.Add("routeName", item["routeName"].ToString()); ht.Add("areaName", item["areaName"].ToString()); ht.Add("deviceName", item["deviceName"].ToString()); ht.Add("T_ITEMPOSITION", item["T_ITEMPOSITION"].ToString()); ht.Add("T_ITEMDESC", item["T_ITEMDESC"].ToString()); ht.Add("type", item["type"].ToString()); ht.Add("sTime", startTime); ht.Add("eTime", endTime); ht.Add("cTime", cTime); ht.Add("uTime", uTime); ht.Add("value", item["value"].ToString()); ht.Add("state", item["state"].ToString()); ht.Add("status", item["status"].ToString()); list.Add(ht); } object obj = new { total = count, rows = list }; string result = JsonConvert.SerializeObject(obj); Response.Write(result); Response.End(); }
public async Task <IHttpActionResult> Get(int id) { Plan j = null; try { PlanBLL bll = new PlanBLL(_unit); j = bll.GetByID(id); } catch (Exception ex) { LogHelper.Error(_log, ex.ToString()); return(InternalServerError(ex)); } return(Ok(j)); }
public async Task <IHttpActionResult> Get(int?zoneId) { List <Plan> slist = null; try { var currentUser = await GetCurrentUser(); PlanBLL bll = new PlanBLL(_unit); slist = bll.GetListByZone(currentUser.Id, zoneId).ToList(); } catch (Exception ex) { LogHelper.Error(_log, ex.ToString()); return(InternalServerError(ex)); } return(Ok(slist)); }
public ActionResult Edit(PlanInfo info) { PlanInfo infoExist = PlanBLL.GetList(p => p.ID == info.ID).FirstOrDefault(); if (null == infoExist) { return(Json(new APIJson(-1, "parms error"))); } info.Enable = true; infoExist.DateBegin = info.DateBegin; infoExist.DateEnd = info.DateEnd; infoExist.AgenterName = info.AgenterName; infoExist.Mount = info.Mount; infoExist.Enable = info.Enable; infoExist.MarketLevel = info.MarketLevel; infoExist.TypeFlag = info.TypeFlag; infoExist.SortID = info.SortID; if (PlanBLL.Edit(infoExist)) { return(Json(new APIJson(0, "提交成功", info))); } return(Json(new APIJson(-1, "提交失败", info))); }
static void Main(string[] args) { System.Console.WriteLine("Create Client"); ClientBLL clientBLL = new ClientBLL(); IClient clientThomas = clientBLL.Create("Thomas", new DateTime(1980, 3, 25)); System.Console.WriteLine("Create Plan"); PlanBLL planBLL = new PlanBLL(); IPlan planNoSMS; try { planNoSMS = planBLL.Create("No SMS <3", -2, 0, 15, -.30M, 0.15M, true); } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); planNoSMS = planBLL.Create("No SMS ", -1, 0, 15, .30M, 0.15M, true); } System.Console.WriteLine("Create Subscription"); SubscriptionBLL subscriptionBLL = new SubscriptionBLL(); ISubscription subscriptionThomas = subscriptionBLL.Create( planNoSMS.GetPlanId(), clientThomas.GetClientId(), "06234235262", DateTime.Now, null); String phoneNumber = subscriptionThomas.GetPhoneNumber(); System.Console.WriteLine("Searching client by phone number : " + phoneNumber); IClient clientThomas2 = clientBLL.GetByPhoneNumber(phoneNumber); if (clientThomas2 != null) { System.Console.WriteLine("client Thomas found by phone number : " + clientThomas2.GetClientId()); } else { System.Console.WriteLine("client not found"); } System.Console.WriteLine("Update phone number"); subscriptionThomas.SetPhoneNumber("0623425262"); subscriptionBLL.Update(subscriptionThomas); System.Console.WriteLine(); System.Console.WriteLine("List all clients"); foreach (IClient client in clientBLL.GetAll()) { System.Console.WriteLine(client.GetName() + " id " + client.GetClientId() + " borne on " + client.GetBirthday().ToShortDateString()); } System.Console.WriteLine(); System.Console.WriteLine("List all plans"); foreach (IPlan plan in planBLL.GetAll()) { System.Console.WriteLine(plan.GetName() + " id " + plan.GetPlanId()); } System.Console.WriteLine(); System.Console.WriteLine("List all subscriptions"); foreach (ISubscription subscription in subscriptionBLL.GetAll()) { System.Console.WriteLine(subscription.GetPhoneNumber() + " id " + subscription.GetSubscriptionId()); } System.Console.WriteLine(); System.Console.WriteLine("Creating some SMS and Call History"); List <IHistory> Histories = new List <IHistory>(); HistoryBLL historyBLL = new HistoryBLL(); string[] phone_nums = { "(1) (415) 123-1234", "(415) 123-1234", "1-800-123-1234", "206/782-8410", "206.782.8410", "05324225543", "+335324225543", "206 782 8410 ", "206-782-8410", "(206) 782-8410", "555-555-5555", "05324+343" }; foreach (string phone_num in phone_nums) { try { System.Console.WriteLine("Create hist with : " + phone_num); ISMSHistory history = historyBLL.CreateSMS(subscriptionThomas.GetSubscriptionId(), DateTime.Now, phone_num, "+33"); ICallHistory call = historyBLL.CreateVoice(subscriptionThomas.GetSubscriptionId(), DateTime.Now, phone_num, "+33", 35); Thread.Sleep(1000); Histories.Add(history); Histories.Add(call); } catch (InvalidFormatException e) { System.Console.WriteLine(e.Message); } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } } System.Console.WriteLine(); System.Console.WriteLine("List all history"); foreach (IHistory histor in historyBLL.GetAll()) { if (histor is ICallHistory) { System.Console.WriteLine("Phone call : " + histor.GetTimestamp() + " FROM : " + subscriptionBLL.GetById(histor.GetSubscriptionId()).GetPhoneNumber() + " TO : " + histor.GetDestinationNumber() + " DURING : " + ((ICallHistory)histor).GetDuration() + " Seconds"); } else { System.Console.WriteLine("SMS : " + histor.GetTimestamp() + " FROM : " + subscriptionBLL.GetById(histor.GetSubscriptionId()).GetPhoneNumber() + " TO : " + histor.GetDestinationNumber()); } historyBLL.Delete(histor); } System.Console.WriteLine(); System.Console.WriteLine("Creating some options"); OptionBLL optionBLL = new OptionBLL(); IOption option = optionBLL.Create("SMSBooster", 0, 100, 10, false); System.Console.WriteLine(); System.Console.WriteLine("List all options"); foreach (IOption opt in optionBLL.GetAll()) { System.Console.WriteLine("Option : " + opt.GetName() + " minute limit : " + opt.GetMinuteLimit() + " sms limit : " + opt.GetSMSLimit() + " price : " + opt.GetPrice() + " is available : " + opt.GetIsAvailable()); } System.Console.WriteLine(); System.Console.WriteLine("Creating SubOption"); SubOptionBLL subOptionBLL = new SubOptionBLL(); ISubOption subOption = subOptionBLL.Create(subscriptionThomas.GetSubscriptionId(), option.GetOptionId(), DateTime.Today, DateTime.Today.AddDays(10)); System.Console.WriteLine(); System.Console.WriteLine("Listing SubOptions"); foreach (ISubOption opt in subOptionBLL.GetAll()) { string res = "SubOption subscriptor : " + subscriptionBLL.GetById(opt.GetSubscriptionId()).GetPhoneNumber() + " for option : " + optionBLL.GetById(opt.GetOptionId()).GetName() + " Started on : " + opt.GetStartDate().ToShortDateString(); if (opt.GetEndDate() != null) { res += " Ending on : " + ((DateTime)opt.GetEndDate()).ToShortDateString(); } System.Console.WriteLine(res); } System.Console.WriteLine(); System.Console.WriteLine("Trying to break the system "); int nb = 0; try { clientBLL.Create("Thoma$", new DateTime(1980, 3, 25)); System.Console.WriteLine("Got {0} :) ", ++nb); } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { clientBLL.Create("Thomas", DateTime.Today.AddDays(3)); System.Console.WriteLine("Got {0} :) ", ++nb); } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { planBLL.Create("<3", 0, 0, 0, 0, 0, false); System.Console.WriteLine("Got {0} :) ", ++nb); } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { planBLL.Create("love", -2, -2, -2, -2, -2, false); System.Console.WriteLine("Got one :) "); nb++; } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { subscriptionBLL.Create(1, 1, "+3345566786", DateTime.Today, DateTime.Today.AddDays(-3)); System.Console.WriteLine("Got one :) "); nb++; } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { optionBLL.Create("<3", -2, -2, -1, true); System.Console.WriteLine("Got one :) "); nb++; } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } try { subOptionBLL.Create(1, 1, DateTime.Today, DateTime.Today.AddDays(-3)); System.Console.WriteLine("Got one :) "); nb++; } catch (DbEntityValidationException dbEx) { printValidationException(dbEx); } subOptionBLL.Delete(subOption); optionBLL.Delete(option); subscriptionBLL.Delete(subscriptionThomas); clientBLL.Delete(clientThomas); planBLL.Delete(planNoSMS); System.Console.Read(); }
public void GetString() { string idkey = Request.Cookies["ID_KEY"].Value.ToString(); string userID = bl.GetUserNameById(idkey, out errMsg); PlanBLL plan = new PlanBLL(); int page = Convert.ToInt32(Request["page"].ToString()); int rows = Convert.ToInt32(Request["rows"].ToString()); DataTable dt = plan.GetPlan(userID, Convert.ToDateTime(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")), (page - 1) * rows + 1, page * rows); count = plan.GetPlanCount(userID, "0", "0", "0", Convert.ToDateTime(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59"))); IList <Hashtable> list = new List <Hashtable>(); foreach (DataRow item in dt.Rows) { Hashtable ht = new Hashtable(); string startTime = item["sTime"].ToString(); string endTime = item["eTIme"].ToString(); string cTime = item["cTime"].ToString(); string uTime = item["uTime"].ToString(); ht.Add("ID", item["ID"]); ht.Add("routeName", item["routeName"].ToString()); ht.Add("areaName", item["areaName"].ToString()); ht.Add("deviceName", item["deviceName"].ToString()); ht.Add("T_ITEMPOSITION", item["T_ITEMPOSITION"].ToString()); ht.Add("T_ITEMDESC", item["T_ITEMDESC"].ToString()); ht.Add("type", item["type"].ToString()); ht.Add("sTime", startTime); ht.Add("eTime", endTime); ht.Add("cTime", cTime); ht.Add("uTime", uTime); ht.Add("value", item["value"].ToString()); ht.Add("RouteID", item["ROUTEID"].ToString()); ht.Add("AreaID", item["AREAID"].ToString()); ht.Add("DeviceID", item["DEVICEID"].ToString()); ht.Add("ItemID", item["ITEMID"].ToString()); if (item["status"].ToString() == "新任务") { if (DateTime.Now > Convert.ToDateTime(endTime)) { ht.Add("status", "缺陷"); } } else { ht.Add("status", item["status"].ToString()); } ht.Add("state", item["state"].ToString()); list.Add(ht); } object obj = new { total = count, rows = list }; string result = JsonConvert.SerializeObject(obj); Response.Write(result); Response.End(); }