public async Task <Picture> AddAsync(int tempFileId, bool isMain, int linkedObjectId, LinkedObjectType linkedObjectType) { Contracts.Assert(tempFileId != 0); Contracts.Assert(linkedObjectId != 0); try { var tempFile = await _context.TempFiles.FirstAsync(tf => tf.Id == tempFileId); Picture picture = new Picture { Data = tempFile.Data, Filename = tempFile.Filename, IsMain = isMain, LinkedObjectId = linkedObjectId, LinkedObjectType = linkedObjectType }; _context.Pictures.Add(picture); _context.TempFiles.Remove(tempFile); await _context.SaveChangesAsync(); return(picture); } catch (Exception ex) { ErrorLogger.Log("CANNOT ADD PICTURE", ex); throw; } }
public async Task <Reservation> AddAsync(Reservation reservation) { try { UserOperations userOperations = new UserOperations(_context); var user = await userOperations.GetAsync(reservation.UserId); if (user == null) { await userOperations.RegisterAsync(reservation.User.Email); } reservation.Created = DateTime.Now; _context.Reservations.Add(reservation); await _context.SaveChangesAsync(); var newReservation = await this.GetAsync(reservation.Id); SendEmail(newReservation); return(newReservation); } catch (Exception ex) { ErrorLogger.Log("CANNOT ADD RESERVATION", ex); throw; } }
public async Task <Organizer> AddAsync(Organizer organizer) { _context.Organizers.Add(organizer); await _context.SaveChangesAsync(); return(organizer); }
public async Task <City> UpdateAsync(City city) { var cityFromDb = await _context.Cities.FirstOrDefaultAsync(c => c.Id == city.Id); cityFromDb.Name = city.Name; await _context.SaveChangesAsync(); return(cityFromDb); }
public async Task <Activity> AddAsync(Activity activity) { try { _context.Activities.Add(activity); await _context.SaveChangesAsync(); return(activity); } catch (Exception ex) { ErrorLogger.Log("CANNOT ADD ACTIVITY", ex); throw; } }
public async Task RemoveAllTempFiles() { var tempFiles = _context.TempFiles; _context.TempFiles.RemoveRange(tempFiles); await _context.SaveChangesAsync(); }
public async Task <Interest> UpdateAsync(Interest interest) { try { var existingInterest = await _context.Interests.FirstOrDefaultAsync(i => i.Id == interest.Id); existingInterest.Name = interest.Name; await _context.SaveChangesAsync(); return(existingInterest); } catch (Exception ex) { ErrorLogger.Log("CANNOT UPDATE INTEREST", ex); throw; } }
/// <summary> /// Обновление пользователя /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <User> UpdateAsync(User user) { var userInDb = await _context.Users.FirstOrDefaultAsync(u => u.Id == user.Id); Contracts.Assert(userInDb != null); userInDb.Name = user.Name; userInDb.CityId = user.CityId; userInDb.Phone = user.Phone; userInDb.PictureId = user.PictureId; userInDb.Role = user.Role; userInDb.Email = user.Email; await _context.SaveChangesAsync(); return(userInDb); }
public async Task <TempFile> UpdateAsync(TempFile tempFile) { try { var tempFileDb = _context.TempFiles.First(tf => tf.Id == tempFile.Id); tempFileDb.Filename = tempFile.Filename; tempFileDb.FormId = tempFile.FormId; tempFileDb.Data = tempFile.Data; await _context.SaveChangesAsync(); return(tempFileDb); } catch (Exception ex) { ErrorLogger.Log("CANNOT UPDATE TEMP_FILE", ex); throw; } }
public async Task <Review> UpdateAsync(Review review) { try { var reviewInDb = await GetAsync(review.Id); reviewInDb.ActivityId = review.ActivityId; reviewInDb.IsChecked = review.IsChecked; reviewInDb.Text = review.Text; reviewInDb.ReplyToReviewId = review.ReplyToReviewId; await _context.SaveChangesAsync(); return(reviewInDb); } catch (Exception ex) { ErrorLogger.Log("CANNOT UPDATE REVIEW", ex); throw; } }
public async Task <int> AddVoice(int userId, VoiceValue voiceValue, int activityId) { var voice = _context.ActivityUserVoices .FirstOrDefault(v => (v.ActivityId == activityId) && (v.UserId == userId)) ?? new ActivityUserVoice { ActivityId = activityId, UserId = userId, }; voice.VoiceValue = voiceValue; if (voice.Id == 0) { _context.ActivityUserVoices.Add(voice); } await _context.SaveChangesAsync(); return(await GetActivityVoices(activityId)); }