コード例 #1
0
ファイル: Model1.Designer.cs プロジェクト: boujnah5207/gadev
 /// <summary>
 /// Deprecated Method for adding a new object to the Budgets EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBudgets(Budget budget)
 {
     base.AddObject("Budgets", budget);
 }
コード例 #2
0
ファイル: Model1.Designer.cs プロジェクト: boujnah5207/gadev
 /// <summary>
 /// Create a new Budget object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="creationDate">Initial value of the CreationDate property.</param>
 /// <param name="companyId">Initial value of the CompanyId property.</param>
 /// <param name="year">Initial value of the Year property.</param>
 /// <param name="isActive">Initial value of the IsActive property.</param>
 /// <param name="isCanceled">Initial value of the IsCanceled property.</param>
 public static Budget CreateBudget(global::System.Int32 id, global::System.DateTime creationDate, global::System.Int32 companyId, global::System.Int32 year, global::System.Boolean isActive, global::System.Boolean isCanceled)
 {
     Budget budget = new Budget();
     budget.Id = id;
     budget.CreationDate = creationDate;
     budget.CompanyId = companyId;
     budget.Year = year;
     budget.IsActive = isActive;
     budget.IsCanceled = isCanceled;
     return budget;
 }
コード例 #3
0
 public ActionResult PartialDetails(Budget budget)
 {
     return PartialView(budget);
 }
コード例 #4
0
        public ActionResult Import(HttpPostedFileBase file, int? id, string name, int? year, string budgetType)
        {
            if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission);
            if (file != null && file.ContentLength <= 0) return Error(Loc.Dic.error_invalid_form);
            if (string.IsNullOrEmpty(budgetType))
                return Error(Loc.Dic.Error_chooseMonthelyOrYearlyBudget);
            if (!(budgetType == "Month" || budgetType == "Year"))
                return Error(Loc.Dic.Error_no_budgetType);

            if (id.HasValue)
            {
                string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, id.Value, budgetType);
                if (moved == "OK") return RedirectToAction("index");
                else return Error(moved);
            }
            else if (year.HasValue)
            {
                if (year.Value > DateTime.Now.Year + 10 || year.Value < DateTime.Now.Year - 1)
                    return Error(Loc.Dic.error_invalid_budget_year);

                using (BudgetsRepository budgetsRepository = new BudgetsRepository(CurrentUser.CompanyId))
                {
                    Budget newBudget = new Budget();
                    newBudget.Name = name;
                    newBudget.Year = year.Value;
                    newBudget.CompanyId = CurrentUser.CompanyId;
                    newBudget.IsActive = false;
                    budgetsRepository.Create(newBudget);
                    string moved = Interfaces.ImportBudget(file.InputStream, CurrentUser.CompanyId, newBudget.Id, budgetType);
                    if (moved == "OK") return RedirectToAction("index");
                    else return Error(moved);
                }

            }
            return Error(Loc.Dic.error_invalid_form);
        }
コード例 #5
0
 public ActionResult Edit(Budget budget)
 {
     if (ModelState.IsValid)
     {
         db.Budgets.Attach(budget);
         db.ObjectStateManager.ChangeObjectState(budget, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", budget.CompanyId);
     return View(budget);
 }
コード例 #6
0
        public ActionResult Create(Budget budget)
        {
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    if (budget.Year >= DateTime.Now.Year)
                    {
                        budget.CompanyId = CurrentUser.CompanyId;
                        budget.IsActive = false;

                        bool wasCreated;
                        using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                        {
                            bool yearExists = budgetRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Year == budget.Year);

                            if (yearExists)
                                return Error(Loc.Dic.error_budgets_year_exists);

                            wasCreated = budgetRep.Create(budget);
                        }

                        if (wasCreated)
                            return RedirectToAction("Index");
                        else
                            return Error(Loc.Dic.error_budgets_create_error);
                    }
                    else
                    {
                        return Error(Loc.Dic.error_budgets_year_passed);
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }