/// <summary> /// Add / Update Ntr Type /// </summary> public NrtType AddUpdateNtrType(NrtType nrtTypeRequest) { NrtType dbVersion = nrtTypeRepository.Find(nrtTypeRequest.NrtTypeId); if (nrtTypeRepository.IsNrtTypeCodeExists(nrtTypeRequest)) { throw new CaresException(Resources.NonRevenueTicket.NrtType.NrtTypeCodeDuplicationError); } if (dbVersion != null) { UpdateNrtTypeProperties(nrtTypeRequest, dbVersion); nrtTypeRepository.Update(dbVersion); } else { dbVersion = new NrtType(); SetNrtTypeProperties(nrtTypeRequest, dbVersion); nrtTypeRepository.Add(dbVersion); } nrtTypeRepository.SaveChanges(); // To Load the proprties return(nrtTypeRepository.GetNrtTypeWithDetails(dbVersion.NrtTypeId)); }
/// <summary> /// Update Nrt Type Properties while updating the instance /// </summary> private void UpdateNrtTypeProperties(NrtType nrtType, NrtType dbVersion) { dbVersion.RecLastUpdatedBy = nrtTypeRepository.LoggedInUserIdentity; dbVersion.RecLastUpdatedDt = DateTime.Now; dbVersion.RowVersion = dbVersion.RowVersion + 1; dbVersion.NrtTypeCode = nrtType.NrtTypeCode; dbVersion.NrtTypeName = nrtType.NrtTypeName; dbVersion.Description = nrtType.Description; dbVersion.NrtTypeKey = nrtType.NrtTypeKey; dbVersion.StandardLifeTime = nrtType.StandardLifeTime; dbVersion.VehicleStatusId = nrtType.VehicleStatusId; }
/// <summary> /// Delete Ntr Type /// </summary> public void DeleteNtrType(long ntrTypeId) { NrtType dbversion = nrtTypeRepository.Find(ntrTypeId); CheckNrtTypeAssociations(ntrTypeId); if (dbversion == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Nrt Type with Id {0} not found!", ntrTypeId)); } nrtTypeRepository.Delete(dbversion); nrtTypeRepository.SaveChanges(); }
/// <summary> /// Crete From web model /// </summary> public static DomainModels.NrtType CreateFrom(this NrtType source) { return(new DomainModels.NrtType { NrtTypeId = source.NrtTypeId, NrtTypeCode = source.NrtTypeCode, NrtTypeName = source.NrtTypeName, Description = source.Description, NrtTypeKey = source.NrtTypeKey, StandardLifeTime = source.StandardLifeTime, VehicleStatusId = source.VehicleStatusId }); }