public String UpdateAlteration(int id, FundsAlteration newAlteration) { using (var context = new SystemDbContext()) { String msg = ""; if (!IsValid(newAlteration, UPDATE, out msg)) { return(msg); } var fundsAlterations = context.Set <FundsAlteration>(); var fundsAlteration = fundsAlterations.Where(x => x.Id == id).FirstOrDefault(); fundsAlteration.Amount = newAlteration.Amount; fundsAlteration.Comment = newAlteration.Comment; fundsAlteration.Date = newAlteration.Date; fundsAlteration.Type = newAlteration.Type; fundsAlteration.Periodic = newAlteration.Periodic; if (!IsValid(fundsAlteration, UPDATE, out msg)) { return(msg); } context.SaveChanges(); return(msg); } }
public EditingForm(FundsAlteration fundsAlteration) { InitializeComponent(); this.fundsAlteration = fundsAlteration; this.numericUpDownEdit.Value = (decimal)fundsAlteration.Amount; this.radioButtonRepeated.Checked = fundsAlteration.Periodic; this.dateTimePickerEdit.Value = (DateTime)fundsAlteration.Date; }
public void DeleteAlteration(int id) { using (var context = new SystemDbContext()) { var fundsAlterations = context.Set <FundsAlteration>(); FundsAlteration fundsAlteration = fundsAlterations .Where(x => x.Id == id) .FirstOrDefault(); if (fundsAlteration != null) { fundsAlterations.Remove(fundsAlteration); } } }
public UpdateForm(Form parent, FundsAlteration fundsAlteration) { InitializeComponent(); this.parent = parent; this.fundsAlteration = fundsAlteration; this.Amount = (decimal)fundsAlteration.Amount; this.Repeated = fundsAlteration.Periodic; this.Date = fundsAlteration.Date.Value; this.ConfirmButton.Text = "Редактирай"; this.ConfirmButton.Click += ButtonUpdate_Click; this.BackButton.Click += ButtonBack_Click; }
public String AddAlteration(double amount, String type, bool isPeriodic, DateTime?dateTime, String comment = null) { using (var context = new SystemDbContext()) { var fundsAlterations = context.Set <FundsAlteration>(); DateTime?dt = (dateTime != null ? dateTime : DateTime.Now); String msg = ""; FundsAlteration fa = new FundsAlteration(amount, type, dt, isPeriodic); if (IsValid(fa, CREATE, out msg)) { fundsAlterations.Add(fa); context.SaveChanges(); } return(msg); } }
public String DeleteAlteration(int id) { using (var context = new SystemDbContext()) { String msg = ""; var fundsAlterations = context.Set <FundsAlteration>(); FundsAlteration fundsAlteration = fundsAlterations .Where(x => x.Id == id) .FirstOrDefault(); if (fundsAlteration != null && IsValid(fundsAlteration, DELETE, out msg)) { fundsAlterations.Remove(fundsAlteration); } context.SaveChanges(); return(msg); } }
private bool IsValid(FundsAlteration fundsAlteration, String type, out String msg) { if (fundsAlteration.Amount <= 0 || (!fundsAlteration.Type.Equals(FundsAlterationTypes.INCOME) && !fundsAlteration.Type.Equals(FundsAlterationTypes.EXPENSE))) { msg = INVALID_DATA; return(false); } //if (fundsAlteration.Periodic) //{ // msg = GENERIC_ERROR; //to be implemented // return false; //} if (fundsAlteration.Type.Equals(FundsAlterationTypes.EXPENSE)) { double balance = this.CalcBalance(); if (fundsAlteration.Amount > balance) { msg = INSUFFICIENT_FUNDS; return(false); } } switch (type) { case "create": msg = ROW_ADDED_SUCCESSFULLY; return(true); case "update": msg = ROW_UPDATED_SUCCESSFULLY; return(true); case "delete": msg = ROW_DELETED_SUCCESSFULLY; return(true); default: msg = "null"; return(true); } // msg = ROW_ADDED_SUCCESSFULLY; // return true; }