81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using EnVisage.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace EnVisage.Code
|
|
{
|
|
public class CalculatesCategoryManager
|
|
{
|
|
private readonly EnVisageEntities _dbContext;
|
|
private readonly bool _isContexLocal = false;
|
|
|
|
public CalculatesCategoryManager(EnVisageEntities dbContext)
|
|
{
|
|
if (dbContext == null)
|
|
{
|
|
_dbContext = new EnVisageEntities();
|
|
_isContexLocal = true;
|
|
}
|
|
else
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_isContexLocal)
|
|
_dbContext.Dispose();
|
|
}
|
|
|
|
#region Public Methods
|
|
/// <summary>
|
|
/// Loads a CalculatesCategory from the database.
|
|
/// </summary>
|
|
/// <param name="value">Unique identifier of the CalculatesCategory .</param>
|
|
/// <param name="isReadOnly">Indicates that object will not be saved later in the code. Use <b>false</b> if you need to save an updated object.</param>
|
|
/// <returns>A <see cref="Expenditure2Expenditure"/> object retrieved from database.</returns>
|
|
public Expenditure2Expenditure Load(Guid? value, bool isReadOnly = true)
|
|
{
|
|
if (value == null || value == Guid.Empty)
|
|
return new Expenditure2Expenditure();
|
|
|
|
return isReadOnly
|
|
? _dbContext.Expenditure2Expenditure.AsNoTracking().FirstOrDefault(t => t.Id == value)
|
|
: _dbContext.Expenditure2Expenditure.Find(value);
|
|
}
|
|
|
|
public void Save(Expenditure2Expenditure model)
|
|
{
|
|
if (model == null)
|
|
throw new ArgumentNullException("model");
|
|
|
|
#region Save CalculatesCategory data
|
|
Expenditure2Expenditure dbObj = null;
|
|
if (model.Id != Guid.Empty)
|
|
dbObj = _dbContext.Expenditure2Expenditure.Find(model.Id);
|
|
if (dbObj == null)
|
|
{
|
|
dbObj = new Expenditure2Expenditure { Id = Guid.NewGuid() };
|
|
}
|
|
//model.CopyTo(dbObj);
|
|
dbObj.FactorType = model.FactorType;
|
|
dbObj.ProcessOrder = model.ProcessOrder;
|
|
dbObj.ParentId = model.ParentId;
|
|
dbObj.ChildId = model.ChildId;
|
|
dbObj.FactorInt = model.FactorInt;
|
|
|
|
if (model.Id == Guid.Empty)
|
|
_dbContext.Expenditure2Expenditure.Add(dbObj);
|
|
else
|
|
_dbContext.Entry(dbObj).State = EntityState.Modified;
|
|
#endregion
|
|
|
|
if (_isContexLocal)
|
|
_dbContext.SaveChanges();
|
|
}
|
|
#endregion
|
|
}
|
|
} |