本文整理匯總了C#中Segator.Loms.Modules.Common.Entities.LomsContext.SaveChanges方法的典型用法代碼示例。如果您正苦於以下問題:C# LomsContext.SaveChanges方法的具體用法?C# LomsContext.SaveChanges怎麽用?C# LomsContext.SaveChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Segator.Loms.Modules.Common.Entities.LomsContext
的用法示例。
在下文中一共展示了LomsContext.SaveChanges方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SaveAddress
public AssociationUserAddress SaveAddress(AssociationUserAddress address)
{
try
{
using (var db = new LomsContext())
{
if (address.SuburbId != null)
{
address.Country = null;
address.State = null;
}
else if (address.StateId != null)
address.Country = null;
db.AssociationUserAddresses.ApplyChanges(address);
db.SaveChanges();
return db.AssociationUserAddresses.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country")
.FirstOrDefault(a => a.Id == address.Id);
}
}
catch (Exception ex)
{
address.AddError("Error", ex.Message);
return address;
}
}
示例2: Change
public EntityResponse<Booking> Change(int bookingId)
{
try
{
using (var db = new LomsContext())
{
db.Connection.Open();
using (var transaction = db.Connection.BeginTransaction())
{
//delete all previus changing attempts
db.Bookings.Where(b => b.OriginalId == bookingId).ForEach(b => db.Bookings.DeleteObject(b));
var originalBooking = db.Bookings.SingleOrDefault(b => b.Id == bookingId);
//copy pick-up and drop-off endpoints
var pickUpEndpoint = db.BookingEndpoints.SingleOrDefault(be => be.Id == originalBooking.PickUpEndpointId).Clone();
var dropOffEndpoint = db.BookingEndpoints.SingleOrDefault(be => be.Id == originalBooking.DropOffEndpointId).Clone();
pickUpEndpoint.ChangeTracker.ChangeTrackingEnabled = true;
dropOffEndpoint.ChangeTracker.ChangeTrackingEnabled = true;
pickUpEndpoint.ChangeTracker.State = ObjectState.Added;
dropOffEndpoint.ChangeTracker.State = ObjectState.Added;
pickUpEndpoint.Id = 0;
dropOffEndpoint.Id = 0;
db.BookingEndpoints.ApplyChanges(pickUpEndpoint);
db.BookingEndpoints.ApplyChanges(dropOffEndpoint);
db.SaveChanges();
//copy booking
var booking = originalBooking.Clone();
booking.ChangeTracker.ChangeTrackingEnabled = true;
booking.ChangeTracker.State = ObjectState.Added;
booking.Id = 0;
if (originalBooking.RefId == 0)
booking.RefId = originalBooking.Id;
else
booking.RefId = originalBooking.RefId;
booking.OriginalId = originalBooking.Id;
booking.Generation = originalBooking.Generation + 1;
booking.PickUpEndpointId = pickUpEndpoint.Id;
booking.DropOffEndpointId = dropOffEndpoint.Id;
booking.OriginalFareTypeId = originalBooking.FareTypeId;
db.Bookings.ApplyChanges(booking);
//update initial booking
originalBooking.Changing = true;
db.Bookings.ApplyChanges(originalBooking);
db.SaveChanges();
//copy fare info
var fareInfo = db.BookingFareInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone();
fareInfo.ChangeTracker.ChangeTrackingEnabled = true;
fareInfo.ChangeTracker.State = ObjectState.Added;
fareInfo.BookingId = booking.Id;
db.BookingFareInfoes.ApplyChanges(fareInfo);
db.SaveChanges();
//copy fareInfo info items
var fareInfoItems = db.BookingFareInfoItems.Where(i => i.BookingId == bookingId);
fareInfoItems.ForEach(i =>
{
var tmp = i.Clone();
tmp.ChangeTracker.ChangeTrackingEnabled = true;
tmp.ChangeTracker.State = ObjectState.Added;
tmp.Id = 0;
tmp.BookingId = booking.Id;
db.BookingFareInfoItems.ApplyChanges(tmp);
});
db.SaveChanges();
//copy passenger info
var passengerInfo = db.BookingPassengerInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone();
passengerInfo.ChangeTracker.ChangeTrackingEnabled = true;
passengerInfo.ChangeTracker.State = ObjectState.Added;
passengerInfo.BookingId = booking.Id;
db.BookingPassengerInfoes.ApplyChanges(passengerInfo);
db.SaveChanges();
//copy passenger info items
var passengerInfoAdults = db.BookingPassengerInfoAdults.Where(i => i.BookingId == bookingId);
passengerInfoAdults.ForEach(i =>
{
var tmp = i.Clone();
tmp.ChangeTracker.ChangeTrackingEnabled = true;
tmp.ChangeTracker.State = ObjectState.Added;
tmp.Id = 0;
tmp.BookingId = booking.Id;
db.BookingPassengerInfoAdults.ApplyChanges(tmp);
});
var passengerInfoChilds = db.BookingPassengerInfoChilds.Where(i => i.BookingId == bookingId);
passengerInfoChilds.ForEach(i =>
{
var tmp = i.Clone();
tmp.ChangeTracker.ChangeTrackingEnabled = true;
tmp.ChangeTracker.State = ObjectState.Added;
tmp.Id = 0;
tmp.BookingId = booking.Id;
db.BookingPassengerInfoChilds.ApplyChanges(tmp);
//.........這裏部分代碼省略.........
示例3: btnActivate_Click
protected void btnActivate_Click(object sender, EventArgs e)
{
string guidStr = Page.RouteData.Values["guid"] as string;
Guid guid;
if (guidStr == null || !Guid.TryParseExact(guidStr, "D", out guid))
{
multiView1.SetActiveView(viewError);
lblError.Text = "Wrong reset guid!";
return;
}
else
{
using (var db = new LomsContext())
{
var pwdReset = db.AssociationUserPasswordResets.FirstOrDefault(a => a.Guid == guid);
if (pwdReset == null)
{
multiView1.SetActiveView(viewError);
lblError.Text = "Wrong reset guid!";
return;
}
//validate password
string pwd = txtPassword.Text.Trim();
string pwd2 = txtConfirmPassword.Text.Trim();
bool notValidated = false;
if (string.IsNullOrEmpty(pwd))
{
notValidated |= lblPasswordNote.Visible = true;
lblComfirmPasswordNote.Text = "Password is required.";
}
if (string.IsNullOrEmpty(pwd2))
{
notValidated |= lblComfirmPasswordNote.Visible = true;
lblComfirmPasswordNote.Text = "Confirm Password is required.";
}
else
if (pwd != pwd2)
{
notValidated |= lblComfirmPasswordNote.Visible = true;
lblComfirmPasswordNote.Text = "Confirm Password does not match to Password.";
}
if (notValidated)
return;
var user = db.AssociationUsers.First(u => u.Id == pwdReset.AssociationUserId);
var membershipUser = Membership.GetUser(user.Email);
if (membershipUser == null)
{
multiView1.SetActiveView(viewError);
lblError.Text = "Wrong email!";
return;
}
string tempPwd = membershipUser.ResetPassword();
membershipUser.ChangePassword(tempPwd, pwd);
db.AssociationUserPasswordResets.DeleteObject(pwdReset);
db.SaveChanges();
multiView1.SetActiveView(viewSuccess);
lblInfo2.Visible = lblInfo21.Visible = lblInfo3.Visible = lblInfo4.Visible = true;
//lblInfo.Text = string.Format("Congratulations {0} {1}!", user.FirstName.ToUpper(), user.LastName.ToUpper());
lblInfo.Text = string.Format("Congratulations!");
lblInfo2.Text = string.Format("Your password has been changed");
lblInfo21.Text = "";
//lblInfo21.Text = string.Format("Your password has been sent to {0}.", user.Email);
lblInfo3.Text = "We look forward to providing you with our on-time guaranteed services for all your journeys.";
lblInfo4.Text = "Once again if you require any further assistance feel free to contact us.";
}
}
}
示例4: SetNoAvailability
public void SetNoAvailability(int bookingId)
{
using (var db = new LomsContext())
{
db.Connection.Open();
using (var transaction = db.Connection.BeginTransaction())
{
var bookingQuote = db.BookingQuotations.Single(q => q.BookingId == bookingId);
bookingQuote.Status = QuotationStatus.NoAvailability;
db.BookingQuotations.ApplyChanges(bookingQuote);
var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Currency", "FareInfo.Items", "AllocatedVehicle").Single(b => b.Id == bookingId);
booking.Status = BookingStatus.QuoteUnavailable;
booking.ClearFareInfo();
booking.ClearAllocatedVehicle();
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
transaction.Commit();
}
}
}
示例5: ActivateSupervisor
public EntityResponse<AssociationUser> ActivateSupervisor(Guid guid)
{
try
{
using (var db = new LomsContext())
{
db.Connection.Open();
using (var transaction = db.Connection.BeginTransaction())
{
var activation = db.AssociationUserTravelAgencyRoleActivations.FirstOrDefault(a => a.Guid == guid);
if (activation == null)
return new EntityResponse<AssociationUser>("Wrong activation guid!");
var role = db.AssociationUserTravelAgencyRoles.First(m => m.UserId == activation.UserId);
if (DateTime.UtcNow > activation.ExpiryTime)
{
role.Status = TravelAgencyStatus.Expired;
db.AssociationUserTravelAgencyRoles.ApplyChanges(role);
db.AssociationUserTravelAgencyRoleActivations.DeleteObject(activation);
db.SaveChanges();
return new EntityResponse<AssociationUser>("Time period for activation is over. Ask group manager to send new invitation.");
}
role.Status = TravelAgencyStatus.Accepted;
db.AssociationUserTravelAgencyRoles.ApplyChanges(role);
db.AssociationUserTravelAgencyRoleActivations.DeleteObject(activation);
db.SaveChanges();
var user = db.AssociationUsers.Single(u => u.Id == role.UserId);
db.SaveChanges();
transaction.Commit();
return new EntityResponse<AssociationUser>() { Entity = user };
}
}
}
catch (Exception ex)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(ex.Message);
if (ex.InnerException != null)
{
builder.AppendLine(ex.InnerException.Message);
if (ex.InnerException.InnerException != null)
builder.AppendLine(ex.InnerException.InnerException.Message);
}
return new EntityResponse<AssociationUser>(builder.ToString());
}
}
示例6: ResetClientPassword
public string ResetClientPassword(string email)
{
try
{
if (string.IsNullOrWhiteSpace(email))
return "Email cannot be empty!";
email = email.Trim().ToLower();
using (var db = new LomsContext())
{
//check id user with such email existed already
var existedUser = (from u in db.AssociationUsers
where u.AssociationId == CurrentAssociationId && u.Email == email
select u).SingleOrDefault();
if (existedUser == null)
return "Not a registered user!";
if (!existedUser.HasOnlineAccess)
return "Not a with online access!";
var pwdReset = db.AssociationUserPasswordResets.SingleOrDefault(r => r.AssociationUserId == existedUser.Id);
if (pwdReset == null)
{
pwdReset = new AssociationUserPasswordReset();
pwdReset.AssociationUserId = existedUser.Id;
}
pwdReset.Guid = Guid.NewGuid();
pwdReset.Time = DateTime.UtcNow.AddHours(2.0);
db.AssociationUserPasswordResets.ApplyChanges(pwdReset);
db.SaveChanges();
var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId);
if (emailProvider != null)
{
var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId);
var uri = HttpContext.Current.Request.Url;
string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port);
string activtionLink = Path.Combine(baseUrl + string.Format("/#PasswordReset/{0}", pwdReset.Guid.ToString("D")));
string contactUsLink = Path.Combine(baseUrl + "/#Contact");
var emailTemplate = new EmailTemplate("PasswordReset");
emailTemplate["UserName"] = existedUser.FullName.ToUpper();
emailTemplate["ActivationLink"] = activtionLink;
emailTemplate["ContactUsLink"] = contactUsLink;
var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html);
emailProvider.SendMail(existedUser.Email, association.Name + " - Reset you Password", emailTemplate.Txt, null, avBody, true);
}
return "";
}
}
catch (Exception ex)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(ex.Message);
if (ex.InnerException != null)
{
builder.AppendLine(ex.InnerException.Message);
if (ex.InnerException.InnerException != null)
builder.AppendLine(ex.InnerException.InnerException.Message);
}
return builder.ToString();
}
}
示例7: ActivateClient
public ActivateClientResponse ActivateClient(Guid guid)
{
try
{
using (var db = new LomsContext())
{
db.Connection.Open();
using (var transaction = db.Connection.BeginTransaction())
{
var activation = db.AssociationUserActivations.FirstOrDefault(a => a.Guid == guid);
if (activation == null)
return new ActivateClientResponse("Wrong activation guid!");
db.AssociationUserActivations.DeleteObject(activation);
db.SaveChanges();
var user = db.AssociationUsers.Single(u => u.Id == activation.UserId);
if (user.AspNetUserId != null)
{
//update membership
var userMembership = Membership.GetUser(user.AspNetUserId);
userMembership.IsApproved = true;
Membership.UpdateUser(userMembership);
transaction.Commit();
return new ActivateClientResponse() { Entity = user };
}
else
return new ActivateClientResponse() { Entity = user, IsPasswordRequired = true };
}
}
}
catch (Exception ex)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(ex.Message);
if (ex.InnerException != null)
{
builder.AppendLine(ex.InnerException.Message);
if (ex.InnerException.InnerException != null)
builder.AppendLine(ex.InnerException.InnerException.Message);
}
return new ActivateClientResponse(builder.ToString());
}
}
示例8: SetSupplierPriorities
public void SetSupplierPriorities(int cityId, int vehicleTypeId, IEnumerable<DispatchSupplier> orderedSuppliers)
{
using (var db = new LomsContext())
{
int priority = 0;
foreach (var supplier in orderedSuppliers)
{
var query = from sc in db.DispatchSupplierCities
join scvt in db.DispatchSupplierCityVehicleTypes on sc.Id equals scvt.SupplierCityId
where sc.SupplierId == supplier.Id && sc.CityId == cityId && scvt.VehicleTypeId == vehicleTypeId
select scvt;
var supplierCityVehicleType = query.SingleOrDefault();
if (supplierCityVehicleType == null)
continue;
supplierCityVehicleType.Priority = priority++;
db.DispatchSupplierCityVehicleTypes.ApplyChanges(supplierCityVehicleType);
}
db.SaveChanges();
}
}
示例9: SaveBookingPendingContectMethod
public BookingStatus SaveBookingPendingContectMethod(int bookingId, PendingContactMethod method)
{
using (var db = new LomsContext())
{
db.Connection.Open();
using (var transaction = db.Connection.BeginTransaction())
{
var booking = db.Bookings.FirstOrDefault(b => b.Id == bookingId);
var time = booking.ExpiryTime - DateTime.UtcNow;
if (time <= TimeSpan.Zero)
return BookingStatus.Expired;
booking.Status = BookingStatus.PendingSubmitted;
booking.PendingContactMethod = method;
db.Bookings.ApplyChanges(booking);
var bookingQuotation = new BookingQuotation() { BookingId = bookingId, Status = QuotationStatus.Pending };
bookingQuotation.Time = GetCityLocalTime(booking.CityId);
db.BookingQuotations.ApplyChanges(bookingQuotation);
db.SaveChanges();
transaction.Commit();
}
return BookingStatus.PendingSubmitted;
}
}
示例10: GetBookingWithFareInfo
public BookingResponse GetBookingWithFareInfo(int bookingId)
{
DebugWriter debugInfoWriter = new DebugWriter();
try
{
DateTime utc = DateTime.UtcNow;
using (var db = new LomsContext())
{
var booking = GetBooking(db, bookingId);
if (!booking.CreatorId.HasValue)
{
booking.CreatorId = CurrentUserId();
booking.PrimaryPassengerId = CurrentUserId();
}
//generate fares
if (booking.Status == BookingStatus.InProgress)
{
if (booking.FareInfo == null)
booking.FareInfo = new BookingFareInfo() { BookingId = booking.Id };
//vehicle availability
if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, true, debugInfoWriter.GetStringBuilder())) //phantom
{
booking.Status = BookingStatus.Fare;
FillBookingWithFareInfo(db, booking, debugInfoWriter);
if (booking.FareInfo.Price == 0)
booking.Status = BookingStatus.Pending;
utc = DateTime.UtcNow;
booking.ExpiryTime = utc.AddMinutes(10.0);
}
else if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, false, debugInfoWriter.GetStringBuilder())) //pending
{
booking.Status = BookingStatus.Pending;
FillBookingWithFareInfo(db, booking, debugInfoWriter);
utc = DateTime.UtcNow;
booking.ExpiryTime = utc.AddMinutes(10.0);
}
else
{
booking.Status = BookingStatus.NoAvailability;
booking.ExpiryTime = null;
}
}
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
booking = GetBooking(db, booking.Id);
return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString(), ServerUtcTime = utc };
}
}
catch (Exception ex)
{
var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() };
response.AddError("Response", ex.ToString());
return response;
}
}
示例11: SaveBookingPickUpTimeDropOffTimeAndPromoCode
public BookingResponse SaveBookingPickUpTimeDropOffTimeAndPromoCode(int bookingId, DateTime pickUptime, DateTime? dropOffTime, string promoCode)
{
DebugWriter debugInfoWriter = new DebugWriter();
try
{
using (var db = new LomsContext())
{
var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Items").FirstOrDefault(b => b.Id == bookingId);
if (booking.PickUpTime != pickUptime)
{
booking.PickUpTime = pickUptime;
booking.OnPickUpTimeChanged();
}
if (booking.DropOffTime != dropOffTime)
{
booking.DropOffTime = dropOffTime;
booking.OnDropOffTimeChanged();
}
if (booking.PromoCode != promoCode)
{
booking.PromoCode = promoCode;
booking.OnPromoCodeChanged();
}
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
booking = GetBooking(db, booking.Id);
return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString() };
}
}
catch (Exception ex)
{
var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() };
response.AddError("Response", ex.ToString());
return response;
}
}
示例12: SaveBookingVehicleType
public BookingResponse SaveBookingVehicleType(int bookingId, int vehicleTypeId)
{
try
{
using (var db = new LomsContext())
{
var booking = GetBooking(db, bookingId);
if (booking.VehicleTypeId != vehicleTypeId)
{
booking.VehicleTypeId = vehicleTypeId;
booking.OnVehicleTypeChanged();
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
}
booking = GetBooking(db, booking.Id);
return new BookingResponse { Booking = booking };
}
}
catch (Exception ex)
{
var response = new BookingResponse();
response.AddError("Response", ex.ToString());
return response;
}
}
示例13: SaveBookingStops
public BookingResponse SaveBookingStops(int bookingId, IEnumerable<BookingStop> stops)
{
try
{
using (var db = new LomsContext())
{
var booking = GetBooking(db, bookingId);
//remove
foreach (var stop in booking.Stops)
if (!stops.Any(s => s.Id == stop.Id))
stop.MarkAsDeleted();
//add
stops.Where(s => s.Id == 0)
.ForEach(s =>
{
s.ClearPropertiesButSkipKeys();
var newStop = new BookingStop();
newStop.SetDataFrom(s);
booking.Stops.Add(newStop);
});
//update
stops.Where(s => s.Id != 0).ForEach(s => booking.Stops.First(bs => bs.Id == s.Id).SetDataFrom(s));
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
booking = GetBooking(db, booking.Id);
return new BookingResponse { Booking = booking };
}
}
catch (Exception ex)
{
var response = new BookingResponse();
response.AddError("Response", ex.ToString());
return response;
}
}
示例14: SaveBookingDropOffEndpoint
public BookingResponse SaveBookingDropOffEndpoint(int bookingId, BookingEndpoint endpoint)
{
try
{
using (var db = new LomsContext())
{
var booking = GetBooking(db, bookingId);
if (booking.DropOffEndpoint.Type != endpoint.Type ||
booking.DropOffEndpoint.Address1 != endpoint.Address1 ||
booking.DropOffEndpoint.SuburbId != endpoint.SuburbId ||
booking.DropOffEndpoint.AirportId != endpoint.AirportId)
{
booking.OnDropOffEndpointChanged();
}
booking.DropOffEndpoint.SetDataFrom(endpoint);
//airport default city
if (booking.JourneyType == JourneyType.ToAirport)
if (booking.DropOffEndpoint.Type == BookingEndpointType.AirportOther || booking.DropOffEndpoint.Type == BookingEndpointType.AirportPrivate)
{
var airportDefaultCity = db.AirportCities.SingleOrDefault(a => a.AirportId == booking.DropOffEndpoint.AirportId && a.IsDefault);
if (airportDefaultCity != null && booking.CityId != airportDefaultCity.CityId)
booking.CityId = airportDefaultCity.CityId;
}
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
booking = GetBooking(db, bookingId);
return new BookingResponse { Booking = booking };
}
}
catch (Exception ex)
{
var response = new BookingResponse();
response.AddError("Response", ex.ToString());
return response;
}
}
示例15: SaveBookingJourneyType
public BookingResponse SaveBookingJourneyType(int bookingId, JourneyType journeyType)
{
try
{
using (var db = new LomsContext())
{
var booking = GetBooking(db, bookingId);
if (booking.JourneyType != journeyType)
{
booking.JourneyType = journeyType;
booking.OnJourneyTypeChanged();
db.Bookings.ApplyChanges(booking);
db.SaveChanges();
}
booking = GetBooking(db, booking.Id);
return new BookingResponse { Booking = booking };
}
}
catch (Exception ex)
{
var response = new BookingResponse();
response.AddError("Response", ex.ToString());
return response;
}
}