本文整理汇总了C#中UnitOfWork.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.SaveChangesAsync方法的具体用法?C# UnitOfWork.SaveChangesAsync怎么用?C# UnitOfWork.SaveChangesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.SaveChangesAsync方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public async Task<ReturnModel<MeetingModel>> Create (MeetingModel meetingModel)
{
var result = new ReturnModel<MeetingModel> { Status = true };
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var MeetingRepository = session.GetRepository<IMeetingRepository>();
var meeting = new Meeting();
meeting.Id = meetingModel.Id;
meeting.ClientId = meetingModel.ClientId;
meeting.Date = meetingModel.Date;
meeting.Weight = meetingModel.Weight;
meeting.Water = meetingModel.Water;
meeting.Muscle = meetingModel.Muscle;
meeting.FatPercentage = meetingModel.FatPercentage;
meeting.MeetingIndex = meetingModel.MeetingIndex;
meeting.ArmMuscleMeasurement = meetingModel.ArmMuscleMeasurement;
meeting.ArmNOMuscleMeasurement = meetingModel.ArmNOMuscleMeasurement;
meeting.HipMeasurement = meetingModel.HipMeasurement;
meeting.StomachMeasurement = meetingModel.StomachMeasurement;
meeting.ThighMeasurement = meetingModel.ThighMeasurement;
meeting.FrontHandFat = meetingModel.FrontHandFat;
meeting.BackHandFat = meetingModel.BackHandFat;
meeting.ThighFat = meetingModel.ThighFat;
meeting.BackFat = meetingModel.BackFat;
meeting.FatAvrg = meetingModel.FatAvrg;
MeetingRepository.Add(meeting);
await session.SaveChangesAsync();
meetingModel.Id = meeting.Id;
result.Result = meetingModel;
return result;
}
}
示例2: Create
public async Task<ReturnModel<UserModel>> Create (UserModel userModel)
{
var result = new ReturnModel<UserModel> { Status = true };
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
if(!(await userRepository.ValidateEmail(userModel.Email,userModel.Id)))
{
result.Error = ("כתובת האמייל כבר בשימוש.");
result.Status = false;
return result;
}
var user = new User();
user.Id = userModel.Id;
user.Email = userModel.Email;
user.Password = userModel.Password;
user.FirstName = userModel.FirstName;
user.LastName = userModel.LastName;
user.BusinessId = userModel.BusinessId;
user.Address = userModel.Address;
user.IsActive = true;
userRepository.Add(user);
await session.SaveChangesAsync();
userModel.Id = user.Id;
userModel.Token = Guid.NewGuid().ToString();
result.Result = userModel;
return result;
}
}
示例3: Create
public async Task<ReturnModel<ClientModel>> Create (ClientModel ClientModel)
{
var result = new ReturnModel<ClientModel> { Status = true };
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var ClientRepository = session.GetRepository<IClientRepository>();
var client = new Client();
client.Id = ClientModel.Id;
client.Name = ClientModel.Name;
client.Email = ClientModel.Email;
client.Phone = ClientModel.Phone;
client.Nationalid = ClientModel.Nationalid;
client.Sex = ClientModel.Sex;
client.Height = ClientModel.Height;
client.Weight = ClientModel.Weight;
client.FatPercentage = ClientModel.FatPercentage;
client.Goal = ClientModel.Goal;
client.Pills = ClientModel.Pills;
client.Supplement = ClientModel.Supplement;
client.RedirectedBy = ClientModel.RedirectedBy;
client.Price = ClientModel.Price;
client.RMR = ClientModel.RMR;
client.UserId = ClientModel.UserId;
ClientRepository.Add(client);
await session.SaveChangesAsync();
ClientModel.Id = client.Id;
result.Result = ClientModel;
return result;
}
}
示例4: CreateUserAsync
private static async Task<bool> CreateUserAsync()
{
var user = BuildNewUser();
using (IDataContextAsync ctx = new AppDataContext())
using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(ctx))
{
IRepositoryAsync<User> userRepository = new Repository<User>(ctx,
unitOfWork);
userRepository.InsertOrUpdateGraph(user);
try
{
await unitOfWork.SaveChangesAsync();
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e);
return false;
}
}
return true;
}
示例5: Create
public async Task<ReturnModel<InvoiceModel>> Create (InvoiceModel invoiceModel)
{
var result = new ReturnModel<InvoiceModel> { Status = true };
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var InvoiceRepository = session.GetRepository<IInvoiceRepository>();
var invoice = new Invoice();
invoice.Id = invoiceModel.Id;
invoice.ClientId = invoiceModel.ClientId;
invoice.Notes = invoiceModel.Notes;
invoice.MeetingId = invoiceModel.MeetingId;
invoice.Number = invoiceModel.Number;
InvoiceRepository.Add(invoice);
await session.SaveChangesAsync();
invoiceModel.Id = invoice.Id;
result.Result = invoiceModel;
return result;
}
}
示例6: Login
public async Task<ReturnModel<UserModel>> Login (string email,string password,bool refresh = true)
{
UserModel model = new UserModel();
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
var user = await userRepository.GetUserByEmailAndPassword(email,password);
var token = refresh ? Guid.NewGuid().ToString() : user.Token;
user.Token = token;
await session.SaveChangesAsync();
var result = new ReturnModel<UserModel>();
result.Result = user == null ? null : new UserModel()
{
Id = user.Id,
Email = user.Email,
Password = user.Password,
FirstName = user.FirstName,
LastName = user.LastName,
Token = token
};
result.Status = user != null;
result.Error = "שם משתמש או סיסמה לא נכונים";
return result;
}
}
示例7: Logout
public async Task<ReturnModel<bool>> Logout (int userId)
{
try
{
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
var user = await userRepository.GetByID(userId);
user.Token = "";
await session.SaveChangesAsync();
return new ReturnModel<bool> { Status = true };
}
}
catch(Exception x)
{
throw x;
}
}
示例8: Delete
public async Task<ReturnModel<bool>> Delete (int userID)
{
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
var user = await userRepository.GetByID(userID);
if(user != null)
{
user.IsActive = false;
await session.SaveChangesAsync();
return new ReturnModel<bool> { Status = true };
}
else
{
return new ReturnModel<bool> { Status = false };
}
}
}
示例9: UpdateImage
public async Task<ReturnModel<bool>> UpdateImage (int userId,string fileName,byte[] bytes)
{
try
{
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
var user = await userRepository.GetByID(userId);
user.LogoFile = fileName;
user.LogoFileBytes = bytes;
await session.SaveChangesAsync();
return new ReturnModel<bool> { Status = true };
}
}
catch(Exception x)
{
throw x;
}
}
示例10: Update
public async Task<ReturnModel<bool>> Update (UserModel userModel)
{
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var userRepository = session.GetRepository<IUserRepository>();
var user = await userRepository.GetByID(userModel.Id);
user.Id = userModel.Id;
user.Email = userModel.Email;
user.Password = userModel.Password;
user.FirstName = userModel.FirstName;
user.LastName = userModel.LastName;
user.BusinessId = userModel.BusinessId;
user.Address = userModel.Address;
await session.SaveChangesAsync();
return new ReturnModel<bool> { Status = true };
}
}
示例11: Update
public async Task<ReturnModel<bool>> Update (InvoiceModel invoiceModel)
{
using(var session = new UnitOfWork<FoodMenuEntities>())
{
var InvoiceRepository = session.GetRepository<IInvoiceRepository>();
var invoice = await InvoiceRepository.GetByID(invoiceModel.Id);
invoice.Id = invoiceModel.Id;
invoice.ClientId = invoiceModel.ClientId;
invoice.Notes = invoiceModel.Notes;
invoice.MeetingId = invoiceModel.MeetingId;
invoice.Number = invoiceModel.Number;
await session.SaveChangesAsync();
return new ReturnModel<bool> { Status = true };
}
}