internal static int AddNew(Service item) { using (var unitOfWork = new UnitOfWork()) { DB.Services dbItem; using (var items = new XPCollection <DB.Services>(unitOfWork)) { dbItem = items.FirstOrDefault(u => u.Name == item.Name && u.User != null && u.User.Id == item.User.Id); if (dbItem != null) { throw new Exception(Resources.Services_AddNew_Такая_услуга_уже_существует_); } dbItem = new DB.Services(unitOfWork) { Name = item.Name, Price = item.Price, PriceType = item.PriceType, Status = item.Status, SiteId = item.SiteId, CompanyId = item.CompanyId }; using (var usrs = new XPCollection <DB.Users>(unitOfWork)) { dbItem.User = usrs.FirstOrDefault(q => q.Id == item.User.Id); } items.Add(dbItem); } unitOfWork.CommitChanges(); return(dbItem.Id); } }
// Получаем данные из бд public Viewer(DB.Services services) { idService = services.idService; Title = GetTitle(services); MainPath = GetPath(services); Duration = GetDuration(services); OldPrice = GetOldPrice(services); Price = GetPrice(services); Discount = GetDiscount(services); }
internal static Service ToModel(DB.Services dbItem, UnitOfWork unitOfWork) { var serv = new Service() { Id = dbItem.Id, Name = dbItem.Name, Price = dbItem.Price, PriceType = dbItem.PriceType, Status = dbItem.Status, SiteId = dbItem.SiteId, CompanyId = dbItem.CompanyId, User = Users.Read(dbItem.User.Id, unitOfWork) }; return(serv); }