Exemplo n.º 1
0
 public Subscription(Guid customerId, DateTime start, SubscriptionType type, PricingPlan pricingPlan)
 {
     CustomerId  = customerId;
     Start       = start;
     Type        = type;
     PricingPlan = pricingPlan;
 }
Exemplo n.º 2
0
        public async Task <ActionResult <PricingPlan> > GetPricingPlanByOrg(int id)
        {
            Organization organization = await unitOfWork.Organizations.SingleOrDefault(o => o.Id == id);

            if (organization == null)
            {
                return(NotFound());
            }
            AppUser user = await userManager.GetUserAsync(User);

            user = unitOfWork.AppUsers.GetUserWithOrgs(user.Id);
            if (user.IsOwnerOfOrg(id))
            {
                PricingPlan pricingPlan = await unitOfWork.PricingPlans.SingleOrDefault(pPlan => pPlan.Id == organization.PricingPlanId);

                if (pricingPlan == null)
                {
                    return(NotFound());
                }
                PricingPlanDto pricingPlanDto = Mapper.Map <PricingPlanDto>(pricingPlan);
                return(Ok(pricingPlanDto));
            }
            else
            {
                return(Unauthorized("You are not an owner!"));
            }
        }
Exemplo n.º 3
0
        //Get Delete
        public ActionResult Delete(int?id, bool?concurrencyError)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
            PricingPlan pricingPlan = db.PricingPlans.Find(id);

            if (pricingPlan == null)
            {
                if (concurrencyError == true)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                return(HttpNotFound());
            }
            if (concurrencyError.GetValueOrDefault())
            {
                if (pricingPlan == null)
                {
                    ViewBag.ConcurrencyErrorMessage = "The record you attempted to delete " + "was deleted by another user after you got the original values. " + "Click the Back to List hyperlink.";
                }
                else
                {
                    ViewBag.ConcurrencyErrorMessage = "The record you attempted to delete " + "was modified by another user after you got the original values. " + "The delete operation was canceled and the current values in the " + "database have been displayed. If you still want to delete this " + "record, click the Delete button again. Otherwise " + "click the Back to List hyperlink.";
                }
            }
            return(View(pricingPlan));
        }
Exemplo n.º 4
0
        public string NewPricingPlan(PricingPlan plan)
        {
            string result = "";

            try
            {
                MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
                QueryDocument query = new QueryDocument();
                query.Add("MeterNo", plan.MeterNo);
                MongoCursor <PricingPlan> mongoCursor = mongo_plan.Query(CollectionNameDefine.MeterPricingPlan, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    var iDelete = new QueryDocument();
                    iDelete.Add("MeterNo", plan.MeterNo);

                    //删除老计划
                    mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
                }

                mongo_plan.Insert(CollectionNameDefine.MeterPricingPlan, plan);
            }
            catch (Exception e) {
                result = e.Message;
            }
            return(result);
        }
Exemplo n.º 5
0
        public string SetPricingPlan(IoT_Pricing info, List <IoT_PricingMeter> meterList)
        {
            string result            = "";
            M_SetParameterService sp = new M_SetParameterService();

            //整理调价参数
            foreach (IoT_PricingMeter m in meterList)
            {
                PricingPlan pp = new PricingPlan()
                {
                    IsUsedLadder   = (bool)info.IsUsed,
                    Ladder         = (int)info.Ladder,
                    MeterType      = info.MeterType,
                    SettlementType = info.SettlementType,
                    Price1         = (decimal)info.Price1,
                    Price2         = (decimal)info.Price2,
                    Price3         = (decimal)info.Price3,
                    Price4         = (decimal)info.Price4,
                    Price5         = (decimal)info.Price5,
                    Gas1           = (decimal)info.Gas1,
                    Gas2           = (decimal)info.Gas2,
                    Gas3           = (decimal)info.Gas3,
                    Gas4           = (decimal)info.Gas4,
                    UseDate        = ((DateTime)info.UseDate).ToString("yyyy-MM-dd")
                };
                pp.MeterNo = m.MeterNo.Trim();
                result     = sp.SetPricingPlan(pp, m);
                //记录调价计划
            }
            return(result);
        }
Exemplo n.º 6
0
        public string PricingPlanFinished(PricingPlan plan)
        {
            string result = "";

            try
            {
                MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
                QueryDocument query = new QueryDocument();
                query.Add("MeterNo", plan.MeterNo);
                MongoCursor <PricingPlan> mongoCursor = mongo_plan.Query(CollectionNameDefine.MeterPricingPlan, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    //删除老计划
                    List <string> list = new List <string>();
                    foreach (PricingPlan p in dataList)
                    {
                        list.Add(p._id.ToString());
                    }

                    var iDelete = new QueryDocument();
                    iDelete.Add("MeterNo", plan.MeterNo);

                    mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
                }
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 设置调价计划
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetPricingPlan(PricingPlan info, IoT_PricingMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_调整价格;    //
                //读取表信息
                info.MeterNo = meter.MeterNo.Trim();
                info.TaskID  = task.TaskID;

                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //2.设置调价计划数据
                DataItem_A010 item_A010 = null;
                CT            ct        = new CT(info.MeterType == "00" ? MeterType.气量表 : MeterType.金额表,
                                                 (bool)info.IsUsedLadder, (JieSuanType)Convert.ToInt16(info.SettlementType.ToString()), ((int)info.Ladder) <= 0 ? 1 : (int)info.Ladder);

                item_A010           = new DataItem_A010(Convert.ToByte(new Random().Next(0, 255)), ct, DateTime.Now);
                item_A010.Price1    = (decimal)info.Price1;
                item_A010.Price2    = (decimal)info.Price2;
                item_A010.Price3    = (decimal)info.Price3;
                item_A010.Price4    = (decimal)info.Price4;
                item_A010.Price5    = (decimal)info.Price5;
                item_A010.UseGas1   = (decimal)info.Gas1;
                item_A010.UseGas2   = (decimal)info.Gas2;
                item_A010.UseGas3   = (decimal)info.Gas3;
                item_A010.UseGas4   = (decimal)info.Gas4;
                item_A010.StartDate = Convert.ToDateTime(info.UseDate);

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_A010.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_A010.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A010.GetBytes());
                cmd.Order          = 1;
                CommandDA.Insert(cmd);


                new PricingPlanDA().NewPricingPlan(info);

                //注:该函数如何进行事务处理,保证所有数据更新都成功。
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
Exemplo n.º 8
0
 public ActionResult Create(PricingPlan pricingPlan)
 {
     if (ModelState.IsValid)
     {
         db.PricingPlans.Add(pricingPlan);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pricingPlan));
 }
Exemplo n.º 9
0
 public void DeletePlan(PricingPlan pp)
 {
     try
     {
         MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
         var iDelete = new QueryDocument();
         iDelete.Add("TaskID", pp.TaskID);
         //删除老计划
         mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
     }
     catch { }
 }
Exemplo n.º 10
0
        //Get Edit
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
            PricingPlan pricingPlan = db.PricingPlans.Find(id);

            if (pricingPlan == null)
            {
                return(HttpNotFound());
            }
            return(View(pricingPlan));
        }
Exemplo n.º 11
0
 public ActionResult Edit(PricingPlan pricingPlan)
 {
     try
     {
         db.Entry(pricingPlan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (DbUpdateConcurrencyException ex)
     {
         var entry         = ex.Entries.Single();
         var clientValues  = (PricingPlan)entry.Entity;
         var databaseEntry = entry.GetDatabaseValues();
         if (databaseEntry == null)
         {
             ModelState.AddModelError(string.Empty, "Unable to save changes.The pricingplan was deleted by another user.");
         }
         else
         {
             var databaseValues = (PricingPlan)databaseEntry.ToObject();
             if (databaseValues.Title != clientValues.Title)
             {
                 ModelState.AddModelError("Title", "Current Value:" + databaseValues.Title);
             }
             if (databaseValues.Head != clientValues.Head)
             {
                 ModelState.AddModelError("Head", "Current Value:" + databaseValues.Head);
             }
             if (databaseValues.Price != clientValues.Price)
             {
                 ModelState.AddModelError("Price", "Curent Value:" + string.Format("{0:c}", databaseValues.Price));
             }
             if (databaseValues.Head1 != clientValues.Head1)
             {
                 ModelState.AddModelError("Head1", "Current Value:" + databaseValues.Head1);
             }
             if (databaseValues.Head2 != clientValues.Head2)
             {
                 ModelState.AddModelError("Head2", "Current Value:" + databaseValues.Head2);
             }
             ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink.");
             pricingPlan.RowVersion = databaseValues.RowVersion;
         }
     }
     catch (RetryLimitExceededException)
     {
         ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator.");
     }
     return(View(pricingPlan));
 }
Exemplo n.º 12
0
        private void UpdatePrices(PricingPlan pricingPlan)
        {
            foreach (var price in pricingPlan.Prices)
            {
                var item = Items.FirstOrDefault(x => x.ItemId == price.ItemId);
                if (item == null)
                {
                    continue;
                }

                item.Price = price.Value;
                item.Value = item.Price * item.Quantity;
            }
        }
Exemplo n.º 13
0
        public async Task <ActionResult <PricingPlan> > PostPricingPlan([FromBody] PricingPlan pricingPlan)
        {
            await unitOfWork.PricingPlans.Add(pricingPlan);

            int result = await unitOfWork.SaveAsync();

            if (result < 1)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok(pricingPlan));
            }
        }
Exemplo n.º 14
0
        private void AddPlan(PricingPlan plan)
        {
            string result = "";

            try
            {
                MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
                DeletePlan(plan.MeterNo);
                mongo_plan.Insert(PPlan, plan);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
        }
Exemplo n.º 15
0
        public async Task <ActionResult <int> > DeletePricingPlan(int id)
        {
            Organization org = await unitOfWork.Organizations.SingleOrDefault(o => o.PricingPlanId == id);

            if (org != null)
            {
                return(BadRequest("Delete Organizations on this pricing plan first"));
            }
            PricingPlan pricingPlan = await unitOfWork.PricingPlans.GetById(id);

            if (pricingPlan == null)
            {
                return(NotFound());
            }

            unitOfWork.PricingPlans.Remove(pricingPlan);
            return(await unitOfWork.SaveAsync());
        }
Exemplo n.º 16
0
 public ActionResult Delete(PricingPlan pricingPlan)
 {
     try
     {
         db.Entry(pricingPlan).State = EntityState.Deleted;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (DbUpdateConcurrencyException)
     {
         return(RedirectToAction("Delete", new { concurrencyError = true, id = pricingPlan.PricingPlanID }));
     }
     catch (DataException)
     {
         ModelState.AddModelError(string.Empty, "Unable to delete. Try again, and if the problem persists contact your system administrator.");
     }
     return(View(pricingPlan));
 }
Exemplo n.º 17
0
        public static Subscription Map(AddSubscriptionCommand command)
        {
            var pricingPlan = new PricingPlan
            {
                CurrencyCode = command.CurrencyCode,
                FlatFee      = command.FlatFee,
                MonthlyRate  = command.MonthlyRate
            };

            var type = new SubscriptionType
            {
                Category     = (Category)Enum.Parse(typeof(Category), command.Category),
                Level        = (Level)Enum.Parse(typeof(Level), command.Level),
                PeriodInDays = command.SubscriptionPeriodInDays,
                ProductId    = command.ProductId
            };

            return(new Subscription(command.CustomerId, command.Start, type, pricingPlan));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> PutPricingPlan(int id, [FromBody] PricingPlanDto pricingPlanVM)
        {
            PricingPlan pPlan = await unitOfWork.PricingPlans.SingleOrDefault(p => p.Id == id);

            if (pPlan == null || pPlan.Id != id)
            {
                return(NotFound());
            }
            pPlan = Mapper.Map(pricingPlanVM, pPlan);
            unitOfWork.PricingPlans.Update(pPlan);
            int result = await unitOfWork.SaveAsync();

            if (result < 1)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok(pPlan));
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 处理主站请求的写操作,并返回应答数据对象
        /// </summary>
        /// <param name="identityCode"></param>
        /// <param name="ser"></param>
        /// <param name="oldItem"></param>
        /// <returns></returns>
        private DataItem DowithWriteData(IdentityCode identityCode, byte ser, DataItem oldItem)
        {
            //在该方法中将写入数据设置到响应变量中
            DataItem item = null;

            switch (identityCode)
            {
            case IdentityCode.写价格表:
                DataItem_A010 item_10 = oldItem as DataItem_A010;
                this.MeterType = ((byte)item_10.CT.CTMeterType).ToString().PadLeft(2, '0');
                if (出厂状态 && item_10.CT.CTMeterType == Common.Item.MeterType.金额表)
                {
                    this.出厂状态           = false;
                    this.IsUsedLadder   = item_10.CT.CTIsLadder;
                    this.Ladder         = item_10.CT.CTLadderNum;
                    this.Price1         = item_10.Price1;
                    this.Gas1           = item_10.UseGas1;
                    this.Price2         = item_10.Price2;
                    this.Gas2           = item_10.UseGas2;
                    this.Price3         = item_10.Price3;
                    this.Gas3           = item_10.UseGas3;
                    this.Price4         = item_10.Price4;
                    this.Gas4           = item_10.UseGas4;
                    this.Price5         = item_10.Price5;
                    this.SettlementType = ((byte)item_10.CT.CTJieSuanType).ToString().PadLeft(2, '0');    //结算类型
                    //设置初次转换为金额表的当前计价参数
                    this.CurrentLadder = 1;
                    this.CurrentPrice  = this.Price1;
                    this.LastGasPoint  = 0;   //上次结算时表底

                    if (this.IsUsedLadder && this.Ladder > this.CurrentLadder)
                    {
                        //计算下一个结算点
                        this.NextSettlementPointGas = this.Gas1;
                        this.SetNextSettlementDateTime();
                    }
                    else
                    {
                        //非阶梯价或无阶梯,-1表示正无穷大
                        this.NextSettlementPointGas = -1;
                    }
                }
                else if (!出厂状态 && item_10.CT.CTMeterType == Common.Item.MeterType.金额表)
                {
                    //调价
                    PricingPlan plan = new PricingPlan();

                    plan.IsUsedLadder   = item_10.CT.CTIsLadder;
                    plan.Ladder         = item_10.CT.CTLadderNum;
                    plan.Price1         = item_10.Price1;
                    plan.Gas1           = item_10.UseGas1;
                    plan.Price2         = item_10.Price2;
                    plan.Gas2           = item_10.UseGas2;
                    plan.Price3         = item_10.Price3;
                    plan.Gas3           = item_10.UseGas3;
                    plan.Price4         = item_10.Price4;
                    plan.Gas4           = item_10.UseGas4;
                    plan.Price5         = item_10.Price5;
                    plan.UseDate        = item_10.StartDate.ToString();
                    plan.MeterType      = ((byte)item_10.CT.CTMeterType).ToString();
                    plan.SettlementType = ((byte)item_10.CT.CTJieSuanType).ToString().PadLeft(2, '0');    //结算类型
                    plan.MeterNo        = this.Mac;
                    this.AddPlan(plan);
                }
                item = new DataItem_A010_Answer(ser, _st1);
                break;

            case IdentityCode.写结算日:
                DataItem_A011 item_11 = oldItem as DataItem_A011;

                this.SettlementDay   = item_11.JieSuanDay;
                this.SettlementMonth = item_11.JieSuanMonth;
                SetNextSettlementDateTime();
                item = new DataItem_A011_Answer(ser);
                break;

            case IdentityCode.写购入金额:
                DataItem_A013 item_13 = oldItem as DataItem_A013;
                if (this.lastBuySer != ser)
                {
                    if (this.lastBuySer != ser)
                    {
                        this.LastSettlementAmount += item_13.BuyMoney;    //写入购买金额
                        this.TotalTopUp           += item_13.BuyMoney;
                        this.CurrentBalance       += item_13.BuyMoney;
                        this.lastBuySer            = ser;
                    }
                }
                item = new DataItem_A013_ASK(ser, item_13.BuyIndex, item_13.BuyMoney);
                break;

            case IdentityCode.写新密钥:
                DataItem_A014 item_14 = oldItem as DataItem_A014;
                this.Key     = item_14.Key;
                this.MKeyVer = item_14.Version;
                item         = new DataItem_A014_ASK(ser, item_14.Version);
                break;

            case IdentityCode.写标准时间:
                item = new DataItem_A015_ASK(ser);
                break;

            case IdentityCode.写阀门控制:
                DataItem_A017 item_17 = oldItem as DataItem_A017;
                this.ValveState      = item_17.IsOpen == true ? "0" : "1";
                this._st1.ValveStatu = item_17.IsOpen;
                item = new DataItem_A017_ASK(ser, this._st1);
                break;

            case IdentityCode.出厂启用:
                item = new DataItem_A019(ser);
                break;

            case IdentityCode.写地址:
                item = new DataItem_A018_Answer(ser);
                break;

            default:
                break;
            }
            Update();
            return(item);
        }