Beispiel #1
0
        public ActionResult Edit(int? id, CommonCodeType? chargeTypeFlag)
        {
            Charge item = null;
            ViewData["ChargeType"] = CommonCodeType.支出记账类型;

            if (id.HasValue)
            {
                item = this.ChargeRepository.Get(id.Value);
            }

            if (item == null )
            {
                item = new Charge();
                if (chargeTypeFlag.HasValue)
                {
                    ViewData["ChargeType"] = chargeTypeFlag.Value;
                }
            }

            return View(item);
        }
Beispiel #2
0
        public ChargeModel(Charge charge)
            : base(charge)
        {
            this.Id = charge.Id;

            if (charge.Account != null)
            {
                this.AccountId = charge.Account.Id;
                this.AccountName = charge.Account.Name;
            }

            this.OldAmount = charge.OldAmount;

            if (charge.ChargeType != null)
            {
                this.ChargeTypeId = charge.ChargeType.Id;
                this.ChargeTypeName = charge.ChargeType.Name;
            }

            this.Amount = charge.Amount;

            if (charge.User != null)
            {
                this.UserId = charge.User.Id;
                this.UserName = charge.User.LoginName;
            }

            this.AutoCreate = charge.AutoCreate.ToString();
            this.Note = charge.Note;
        }
Beispiel #3
0
 public static ChargeModel From(Charge charge)
 {
     return new ChargeModel(charge);
 }
Beispiel #4
0
        public ActionResult SaveOrUpdate(Charge item)
        {
            try
            {
                if (item.Id > 0)
                {
                    item = this.ChargeRepository.Get(item.Id);

                    TryUpdateModel(item);
                }
                else
                {
                    if(item.Account == null)
                        throw new Exception("请选择账户");

                    if (item.Amount == 0)
                        throw new Exception("请输入记账金额");

                    item.OldAmount = item.Account.CurAmount;
                    item.Account.CurAmount -= item.Amount;
                    item.AutoCreate = Yesno.否;
                }

                item.AuditState = AuditState.未审核;

                item = this.ChargeRepository.SaveOrUpdate(item);

                return JsonSuccess(item);

            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }