public Client AddUser(AddUserRequest iur) { try { var cl = new Client { FirstName = iur.FirstName, LastName = iur.LastName, Email = iur.Email, Phone = iur.Phone, Login = iur.Login, Hash = AuthHandler.Create(iur.Password, AuthHandler.CreateSalt()), TokenString = "xxx" }; _advertContext.SaveChanges(); return(cl); } catch (SqlException ex) { return(null); } }
public int CreateAdvertisment(Advertisment advertisment) { _context.Advertisment.Add(advertisment); _context.SaveChanges(); if (advertisment.AdvertismentId.HasValue) { return(advertisment.AdvertismentId.Value); } return(-1); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //Set up identity app.UseAuthentication(); //// Store app services on startup IocContainer.Provider = app.ApplicationServices; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // ensure DB is created using (var context = new AdvertContext()) { context.Database.EnsureCreated(); context.SaveChanges(); } // set the logger SetUpLogger(); // register cors app.UseCors("AllowAdvertsUI"); app.UseHttpsRedirection(); app.UseMvc(); }
public void DeleteuserMessage(int messageId) { var message = GetUserMessageByMessageId(messageId); if (message == null) { throw new MessageNotFoundException(MessagingConstants.MessageNotFoundInfo(messageId)); } //remove the message _context.UserMessages .Remove(message); // confirm changes _context.SaveChanges(); }
public int SaveNotification(Notification notification) { notification.CreatedDateTime = DateTime.UtcNow; if (notification.NotificationBody.Length > 20) { notification.NotificationBody = $"{notification.NotificationBody.Substring(0, 20)}..."; } _context.Notification.Add(notification); _context.SaveChanges(); if (notification.NotificationId != null) { return(notification.NotificationId.Value); } else { return(-1); } }
public void DeleteUser(int id) { using (AdvertContext db = new AdvertContext()) { User user = db.Users.Find(id); if (user != null) { db.Users.Remove(user); } db.SaveChanges(); } }
public static void DeleteAdvert(Advert ad) { try { AdvertContext db = new AdvertContext(options); db.Advert.Remove(ad); db.SaveChanges(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void DeleteAdvert(int id, string phone, string password) { ValidateUser(phone, password); using (AdvertContext db = new AdvertContext()) { Advert advert = db.Advert.Find(id); if (advert != null) { db.Advert.Remove(advert); } db.SaveChanges(); } }
public static void EditAdvert(int id, string name, int animalAge, decimal animalWeight, string kindOfAnimal, string description, string pictureString) { try { AdvertContext db = new AdvertContext(options); Advert ad = new Advert(id, name, animalAge, animalWeight, kindOfAnimal, description, pictureString, DateTime.Now); db.Advert.Update(ad); db.SaveChanges(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void CreateUser(CreateUserRequest request) { User user = new User( request.Name, request.Surname, request.Phone, request.Password); using (AdvertContext db = new AdvertContext()) { db.Users.Add(user); db.SaveChanges(); } }
public AdvertRepositoryTests() { var dbObtions = new DbContextOptionsBuilder <AdvertContext>() .UseInMemoryDatabase(databaseName: "AdvertTest") .Options; _context = new AdvertContext(dbObtions); _context.Database.EnsureDeleted(); _context.Database.EnsureCreated(); #region SeedData //Some mock adverts; var adverts = new[] { new Advert { Id = 1, Title = "Audi A4 Avant", Fuel = FuelType.Diesel, Price = 15000, IsNew = false, Mileage = 35000, FirstRegistration = new DateTime(2015, 10, 1) }, new Advert { Id = 2, Title = "Audi A3", Fuel = FuelType.Diesel, Price = 5000, IsNew = false, Mileage = 135000, FirstRegistration = new DateTime(2015, 10, 1) }, new Advert { Id = 3, Title = "Audi A2", Fuel = FuelType.Gasoline, Price = 3000, IsNew = false, Mileage = 235000, FirstRegistration = new DateTime(2013, 10, 1) }, new Advert { Id = 4, Title = "Audi A5", Fuel = FuelType.Diesel, Price = 25000, IsNew = false, Mileage = 5000, FirstRegistration = new DateTime(2012, 10, 1) }, new Advert { Id = 5, Title = "Volkswagen Golf", Fuel = FuelType.Diesel, Price = 15000, IsNew = false, Mileage = 1000, FirstRegistration = new DateTime(2011, 10, 1) } }.ToList(); _context.Adverts.AddRange(adverts); _context.SaveChanges(); #endregion _advertRepository = new AdvertRepository(_context); }
public void CreateAdvert(CreateAdvertRequest request) { ValidateUser(request.Phone, request.Password); Advert advert = new Advert { District = request.District, Street = request.Street, HouseNumber = request.HouseNumber, Area = request.Area, Floor = request.Floor, Rooms = request.Rooms, Description = request.Description, Price = request.Price, OwnerName = request.OwnerName, OwnerPhone = request.OwnerPhone }; using (AdvertContext db = new AdvertContext()) { db.Advert.Add(advert); db.SaveChanges(); } }
public Advert Add(Advert advert) { _context.Adverts.Add(advert); _context.SaveChanges(); return(advert); }