public async Task <bool> AddLetterBagToShipment(Guid shipmentId, LetterBag letterBagData, bool noTracking = true) { var bag = UOW.Bags.Add(new Bag() { }); await UOW.SaveChangesAsync(); var letterBag = Repository.Add(new DAL.App.DTO.LetterBag { BagId = bag.Id, Count = letterBagData.Count, Weight = letterBagData.Weight, Price = letterBagData.Price }); await UOW.SaveChangesAsync(); var sp = UOW.ShipmentBags.Add(new ShipmentBag { ShipmentId = shipmentId, BagId = bag.Id, }); await UOW.SaveChangesAsync(); return(true); }
public async Task <UserFriend> SendFriendRequest(UserFriend userFriend, Guid?userId = null, bool noTracking = true) { var uf = await GetExistingRequest(userFriend); if (uf == null) { if (userFriend.AppUserId == userFriend.RecipientId) { return(userFriend); } Add(userFriend); await UOW.SaveChangesAsync(); return(userFriend); } if (uf.Accepted) { return(uf); } if (uf.Pending) { return(uf); } uf.Pending = true; await UpdateAsync(uf); await UOW.SaveChangesAsync(); return(uf); }
public async Task <IEnumerable <TeamAnswer> > AddTeamAnswers(TeamAnswer[] teamAnswers, Guid?userId = null, bool noTracking = true) { var ret = new List <TeamAnswer>(); foreach (var answer in teamAnswers) { var x = await FirstExists(answer.TeamId, answer.TopicQuestionId, userId, noTracking); if (x == null) { ret.Add(Add(new TeamAnswer { TeamId = answer.TeamId, TopicQuestionId = answer.TopicQuestionId, Answer = answer.Answer, Correct = answer.Correct, Points = answer.Points })); } else { x.Answer = answer.Answer; x.Correct = answer.Correct; x.Points = answer.Points; await UpdateAsync(x); ret.Add(x); } } await UOW.SaveChangesAsync(); return(ret); }
public async Task <QuestionAnswer[]> AddList(QuestionAnswer[] questions, Guid?userId = null, bool noTracking = true) { foreach (var question in questions) { if (await Repository.ExistsAsync(question.Id)) { continue; } Repository.Add(Mapper.Map(question)); } await UOW.SaveChangesAsync(); return(questions); }
// Get users Cart for index page public async Task <Cart> GetCartViewAsync(Guid?userId = null, bool noTracking = true) { var cart = await GetCartAsync(userId); // check is cart empty or not and set cart status var status = (cart.CartItems.Count != 0) ? CartStatuses.Pending.ToString() : CartStatuses.Empty.ToString(); if (cart.Status != status) { cart.Status = status; await UpdateAsync(cart, userId); await UOW.SaveChangesAsync(); } return(cart); }
public async Task <QuizInvitation> AddWithTeamUser(QuizInvitation quizInvitation, Guid?userId = null, bool noTracking = true) { var qi = await UpdateAsync(quizInvitation); await UOW.SaveChangesAsync(); if (qi.Accepted) { UOW.TeamUsers.Add(new TeamUser { TeamId = quizInvitation.TeamId, AppUserId = quizInvitation.AppUserId, }); } await UOW.SaveChangesAsync(); return(qi); }
public async Task <Team> AddTeamWithMembers(AddTeamDTO addTeamDto, Guid?userId = null, bool noTracking = true) { var team = Repository.Add(Mapper.Map(addTeamDto.Team)); await UOW.SaveChangesAsync(); UOW.TeamUsers.Add(new TeamUser { TeamId = team.Id, AppUserId = team.AppUserId, }); foreach (var memberId in addTeamDto.Members) { UOW.QuizInvitations.Add(new QuizInvitation { TeamId = team.Id, Pending = true, Accepted = false, AppUserId = memberId, }); } await UOW.SaveChangesAsync(); return(Mapper.Map(team)); }