Ejemplo n.º 1
0
        public ActionResult Details(int id = 0)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProject;
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    subProject = subProjectsRep.GetEntity(id);
                }

                if (subProject != null)
                {
                    if (subProject.CompanyId == CurrentUser.CompanyId)
                    {
                        return(View(subProject));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_no_permission));
                    }
                }
                else
                {
                    return(Error(Loc.Dic.error_sub_projects_get_error));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Projects_SubProject projects_subproject)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProjectFromDB;
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    subProjectFromDB = subProjectsRep.GetEntity(projects_subproject.Id);

                    if (subProjectFromDB != null)
                    {
                        if (subProjectFromDB.CompanyId == CurrentUser.CompanyId)
                        {
                            subProjectFromDB.Name = projects_subproject.Name;

                            subProjectsRep.Update(subProjectFromDB);

                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            return(Error(Loc.Dic.error_no_permission));
                        }
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_projects_get_error));
                    }
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProject;

                using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId))
                    using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                    {
                        subProject = subProjectsRep.GetEntity(id);

                        if (subProject != null)
                        {
                            if (subProject.CompanyId == CurrentUser.CompanyId)
                            {
                                subProject.IsActive = false;
                                Projects_SubProject update = subProjectsRep.Update(subProject);

                                if (update != null)
                                {
                                    return(View(subProject));
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_sub_projects_get_error));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_no_permission));
                            }
                        }
                        else
                        {
                            return(Error(Loc.Dic.error_projects_get_error));
                        }
                    }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Delete(int id = 0)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProject;
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    subProject = subProjectsRep.GetEntity(id);
                }

                if (subProject != null)
                {
                    if (subProject.CompanyId == CurrentUser.CompanyId)
                    {
                        return View(subProject);
                    }
                    else
                    {
                        return Error(Loc.Dic.error_no_permission);
                    }
                }
                else
                {
                    return Error(Loc.Dic.error_projects_get_error);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Ejemplo n.º 5
0
        public ActionResult Edit(Projects_SubProject projects_subproject)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProjectFromDB;
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    subProjectFromDB = subProjectsRep.GetEntity(projects_subproject.Id);

                    if (subProjectFromDB != null)
                    {
                        if (subProjectFromDB.CompanyId == CurrentUser.CompanyId)
                        {
                            subProjectFromDB.Name = projects_subproject.Name;

                            subProjectsRep.Update(subProjectFromDB);

                            return RedirectToAction("Index");
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_projects_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_SubProject subProject;

                using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId))
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    subProject = subProjectsRep.GetEntity(id);

                    if (subProject != null)
                    {
                        if (subProject.CompanyId == CurrentUser.CompanyId)
                        {
                            subProject.IsActive = false;
                            Projects_SubProject update = subProjectsRep.Update(subProject);

                            if (update != null)
                                return View(subProject);
                            else
                                return Error(Loc.Dic.error_sub_projects_get_error);
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_projects_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Ejemplo n.º 7
0
        public ActionResult Create(Budgets_Expenses budgets_expenses)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject subProject;

                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                    using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                    {
                        budget = budgetRep.GetEntity(budgets_expenses.BudgetId);
                        project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                        subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);
                    }

                    if (budget != null && project != null && subProject != null)
                    {
                        if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                        {
                            if (project.IsActive && subProject.IsActive)
                            {
                                bool wasCreated;
                                budgets_expenses.CompanyId = CurrentUser.CompanyId;

                                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                {
                                    wasCreated = expensesRep.Create(budgets_expenses);
                                }

                                if (wasCreated)
                                    return RedirectToAction("Index");
                                else
                                    return Error(Loc.Dic.error_expenses_create_error);
                            }
                            else
                            {
                                return Error(Loc.Dic.error_invalid_form);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_database_error);
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Ejemplo n.º 8
0
        public ActionResult Edit(Budgets_Expenses budgets_expenses)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Expenses expenseFromDB;
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject subProject;

                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                    using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                    {
                        expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id);

                        budget = budgetRep.GetEntity(budgets_expenses.BudgetId);
                        project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                        subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);

                        if (expenseFromDB != null)
                        {
                            if (budget != null && project != null && subProject != null)
                            {
                                if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                                {
                                    if (project.IsActive && subProject.IsActive)
                                    {
                                        if (budgets_expenses.Amount < expenseFromDB.Amount)
                                        {
                                            decimal? allocatedToExpense;
                                            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                            {
                                                allocatedToExpense = allocationsRep.GetList()
                                                    .Where(x => x.ExpenseId == expenseFromDB.Id)
                                                    .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount);
                                            }

                                            if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount)
                                                return Error(Loc.Dic.error_expenses_allocations_exeeds_amount);
                                        }

                                        expenseFromDB.BudgetId = budgets_expenses.BudgetId;
                                        expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId;
                                        expenseFromDB.SubProjectId = budgets_expenses.SubProjectId;
                                        expenseFromDB.Amount = budgets_expenses.Amount;
                                        expenseFromDB.CustomName = budgets_expenses.CustomName;

                                        Budgets_Expenses update = expensesRep.Update(expenseFromDB);

                                        if (update != null)
                                            return RedirectToAction("Index");
                                        else
                                            return Error(Loc.Dic.error_expenses_create_error);
                                    }
                                    else
                                    {
                                        return Error(Loc.Dic.error_invalid_form);
                                    }
                                }
                                else
                                {
                                    return Error(Loc.Dic.error_no_permission);
                                }
                            }
                            else
                            {
                                return Error(Loc.Dic.error_database_error);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_expenses_get_error);
                        }
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Ejemplo n.º 9
0
        public ActionResult Edit(Budgets_Expenses budgets_expenses)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Expenses       expenseFromDB;
                    Budget                 budget;
                    Projects_ParentProject project;
                    Projects_SubProject    subProject;

                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                        using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                            using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                                {
                                    expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id);

                                    budget     = budgetRep.GetEntity(budgets_expenses.BudgetId);
                                    project    = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                                    subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);

                                    if (expenseFromDB != null)
                                    {
                                        if (budget != null && project != null && subProject != null)
                                        {
                                            if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                                            {
                                                if (project.IsActive && subProject.IsActive)
                                                {
                                                    if (budgets_expenses.Amount < expenseFromDB.Amount)
                                                    {
                                                        decimal?allocatedToExpense;
                                                        using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                                        {
                                                            allocatedToExpense = allocationsRep.GetList()
                                                                                 .Where(x => x.ExpenseId == expenseFromDB.Id)
                                                                                 .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount);
                                                        }

                                                        if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_expenses_allocations_exeeds_amount));
                                                        }
                                                    }

                                                    expenseFromDB.BudgetId        = budgets_expenses.BudgetId;
                                                    expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId;
                                                    expenseFromDB.SubProjectId    = budgets_expenses.SubProjectId;
                                                    expenseFromDB.Amount          = budgets_expenses.Amount;
                                                    expenseFromDB.CustomName      = budgets_expenses.CustomName;

                                                    Budgets_Expenses update = expensesRep.Update(expenseFromDB);

                                                    if (update != null)
                                                    {
                                                        return(RedirectToAction("Index"));
                                                    }
                                                    else
                                                    {
                                                        return(Error(Loc.Dic.error_expenses_create_error));
                                                    }
                                                }
                                                else
                                                {
                                                    return(Error(Loc.Dic.error_invalid_form));
                                                }
                                            }
                                            else
                                            {
                                                return(Error(Loc.Dic.error_no_permission));
                                            }
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_database_error));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_expenses_get_error));
                                    }
                                }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Ejemplo n.º 10
0
        public ActionResult Create(Budgets_Expenses budgets_expenses)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject    subProject;

                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                            using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                            {
                                budget     = budgetRep.GetEntity(budgets_expenses.BudgetId);
                                project    = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                                subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);
                            }

                    if (budget != null && project != null && subProject != null)
                    {
                        if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                        {
                            if (project.IsActive && subProject.IsActive)
                            {
                                bool wasCreated;
                                budgets_expenses.CompanyId = CurrentUser.CompanyId;

                                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                {
                                    wasCreated = expensesRep.Create(budgets_expenses);
                                }

                                if (wasCreated)
                                {
                                    return(RedirectToAction("Index"));
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_expenses_create_error));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_invalid_form));
                            }
                        }
                        else
                        {
                            return(Error(Loc.Dic.error_no_permission));
                        }
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }