public static int CreateOtherAsset(OtherAssetCreateViewModel model, string username)
        {
            int      result   = 0;
            DateTime current  = DateTime.Now;
            Entities entities = new Entities();

            //Create otherAsset
            Assets otherAsset = new Assets();

            otherAsset.AssetName   = model.Name;
            otherAsset.Value       = model.Value.Value;
            otherAsset.StartDate   = current;
            otherAsset.CreatedDate = current;
            otherAsset.CreatedBy   = Constants.Constants.USER;
            otherAsset.AssetType   = (int)Constants.Constants.ASSET_TYPE.OTHERS;
            otherAsset.ObtainedBy  = (int)Constants.Constants.OBTAIN_BY.CREATE;
            otherAsset.Username    = username;

            Incomes income = new Incomes();

            income.Name        = "Thu nhập từ " + otherAsset.AssetName;
            income.Value       = model.Income.HasValue ? model.Income.Value : 0;
            income.IncomeDay   = 1;
            income.StartDate   = current;
            income.CreatedDate = current;
            income.CreatedBy   = Constants.Constants.USER;
            income.IncomeType  = (int)Constants.Constants.INCOME_TYPE.OTHER_ASSET_INCOME;
            income.Username    = username;
            otherAsset.Incomes1.Add(income);

            entities.Assets.Add(otherAsset);
            result = entities.SaveChanges();
            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult _OtherAssetForm(OtherAssetCreateViewModel model)
        {
            if (OtherAssetQueries.CheckExistOtherAsset(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistAsset", "Tài sản này đã tồn tại, vui lòng nhập tên khác");
            }

            if (ModelState.IsValid)
            {
                string user   = UserQueries.GetCurrentUsername();
                int    result = OtherAssetQueries.CreateOtherAsset(model, user);
                if (result > 0)
                {
                    return(Content("success"));
                }
                else
                {
                    return(Content("failed"));
                }
            }
            else
            {
                model.IsInDebt = false;
                return(PartialView("_OtherAssetForm", model));
            }
        }