public JsonResult Edit(string id, BudgetEntity budget) { var budgetbll = new BudgetBLL(); var success = true; var message = "保存成功!"; try { if (string.IsNullOrEmpty(id)) { budgetbll.Add(budget); } else { budgetbll.Modify(budget); } } catch (Exception e) { success = false; message = e.Message; } return(Json(new AjaxResult() { type = success ? ResultType.success : ResultType.error, message = message })); }
private BudgetResponse ToModel(BudgetEntity budgetEntity) { IEnumerable <BudgetAllocation> budgetAllocations = budgetEntity.BudgetAllocations.Select(a => { return(ToModel(a)); }).ToArray(); return(new BudgetResponse() { Id = budgetEntity.Id, ReferenceId = budgetEntity.ReferenceId, SpendCategoryId = budgetEntity.SpendCategoryId, CareHomeId = budgetEntity.CareHomeId, Name = budgetEntity.Name, DateFrom = budgetEntity.DateFrom, DateTo = budgetEntity.DateTo, Description = budgetEntity.Description, PoPrefix = budgetEntity.PoPrefix, Status = budgetEntity.Status, Reason = budgetEntity.Reason, CreatedById = budgetEntity.CreatedById, UpdatedById = budgetEntity.UpdatedById, BudgetAllocations = budgetAllocations }); }
public bool Delete(BudgetEntity budgetEntity) { try { if (budgetEntity != null) { context.BudgetsContracts.RemoveRange(new BudgetsContracts { BudgetId = budgetEntity.Id, SupplierId = budgetEntity.SupplierId, CustomerId = budgetEntity.CustomerId }); context.Budgets.Remove(new Budgets { BudgetId = budgetEntity.Id, BudgetName = budgetEntity.Name, CustomerId = budgetEntity.CustomerId, SupplierId = budgetEntity.SupplierId }); context.SaveChanges(); return(true); } return(false); } catch (Exception e) { throw e; } }
/// <summary> /// Converts the entity to a data transfer object. /// </summary> /// <param name="entity">The entity.</param> /// <returns>The data transfer object.</returns> public static Budget AsBudget(this BudgetEntity entity) { if (entity.Category == null) { throw new ArgumentNullException(nameof(entity.Category)); } return(new Budget { Id = entity.Id, Amount = entity.Amount, Spent = entity.Spent, StartDate = entity.StartDate.ToDateString(), EndDate = entity.EndDate.ToDateString(), CategoryId = entity.CategoryId, Category = entity.Category.AsCategory(), }); }
public BudgetResponse Insert(BudgetRequest budgetRequest) { // For Inserts, request comes with ONE allocation entity. User can save ONLY ONE AMOUNT. But entity is handled as multiple (1-many) if (budgetRequest.BudgetAllocations.FirstOrDefault().Approved == Constants.BUDGET_APPROVED) { budgetRequest.BudgetAllocations.FirstOrDefault().ApprovedById = budgetRequest.CreatedById; budgetRequest.BudgetAllocations.FirstOrDefault().ApprovedDate = DateTime.Now; } // Ensure all allocations has updated id and date.. budgetRequest.BudgetAllocations.ForEach(a => { a.UpdatedById = budgetRequest.CreatedById; }); // Find start and end dates when the budget type is 'Monthly' if (budgetRequest.BudgetType == BudgetType.Monthly) { IEnumerable <DatePair> dates = GenerateMonthStartEndDates(budgetRequest.BudgetMonth, 1); budgetRequest.DateFrom = dates.First().StartDate; budgetRequest.DateTo = dates.First().EndDate; } // Recurring budgets. Month starts at 1. 1=Jan. If less than Zero, than no recurring budgets. BudgetEntity inserted = null; BudgetEntity[] budgetEntities; if (budgetRequest.NumberOfMonths > 0) { // Recurring budget budgetEntities = CreateRecurringBudgets(budgetRequest); } else { // Standard insert. ONE budget entity. make it array so imple is easier budgetEntities = new List <BudgetEntity>() { ToEntity(budgetRequest) }.ToArray(); } inserted = _spendBudgetDataProvider.Insert(budgetEntities); return(ToModel(inserted)); }
public bool Edit(BudgetEntity budgetEntity) { try { if (budgetEntity != null) { var oldBudget = context.Budgets.Find(budgetEntity.Id, budgetEntity.CustomerId, budgetEntity.SupplierId); if (oldBudget != null) { oldBudget.BudgetName = budgetEntity.Name; context.SaveChanges(); return(true); } } return(false); } catch (Exception e) { throw e; } }
public void AddToBudgetEntitySet(BudgetEntity budgetEntity) { base.AddObject("BudgetEntitySet", budgetEntity); }
public static BudgetEntity CreateBudgetEntity(int budgetId, string name, double startAmount, global::System.DateTime startDate) { BudgetEntity budgetEntity = new BudgetEntity(); budgetEntity.BudgetId = budgetId; budgetEntity.Name = name; budgetEntity.StartAmount = startAmount; budgetEntity.StartDate = startDate; return budgetEntity; }
public ViewResult Detail(string id) { var categories = new List <SelectListItem>() { new SelectListItem() { Value = "材料费", Text = "材料费" }, new SelectListItem() { Value = "修理费", Text = "修理费" } }; ViewData["categories"] = categories; var year = DateTime.Now.Year; var years = new List <SelectListItem>(); for (int i = year; i <= year + 5; i++) { years.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() }); } ViewData["years"] = years; var user = OperatorProvider.Provider.Current(); var costdept = Config.GetValue("CostDept"); var deptbll = new DepartmentBLL(); var dept = new DepartmentBLL().GetAuthorizationDepartment(user.DeptId); var subdepts = default(List <DepartmentEntity>); if (dept.FullName == costdept) { dept = deptbll.GetRootDepartment(); } subdepts = deptbll.GetSubDepartments(dept.DepartmentId, "班组"); var depts = subdepts.OrderBy(x => x.EnCode).Select(x => new SelectListItem() { Value = x.DepartmentId, Text = x.FullName }).ToList(); ViewData["depts"] = depts; ViewBag.id = id; var budget = default(BudgetEntity); if (string.IsNullOrEmpty(id)) { budget = new BudgetEntity() { Year = DateTime.Now.Year.ToString() }; } else { var budgetbll = new BudgetBLL(); budget = budgetbll.GetDetail(Guid.Parse(id)); } return(View(budget)); }
public async Task <BudgetEntity[]> GetBudgetsFromFinance(BudgetEntity customer) { //TODO: connect finance serivce , stuck at orit responbilty return(null); }