public string UpdateCustomer(Customer customer) { var customerFromDb = _db.Customer.Where(c => c.Id == customer.Id && c.IsActive == true).FirstOrDefault(); if (customerFromDb != null) { customerFromDb.Email = customer.Email; var salt = AuthenticationHelper.GenerateSalt(10); var password = AuthenticationHelper.EncodePassword(customer.Password, salt); customerFromDb.Password = password; customerFromDb.Salt = salt; customerFromDb.Address1 = customer.Address1; customerFromDb.Address2 = customer.Address2; customerFromDb.Comments = customer.Comments; customerFromDb.ContactNo = customer.ContactNo; customerFromDb.Name = customer.Name; customerFromDb.UpdatedDate = DateTime.Now; customerFromDb.Zipcode = customer.Zipcode; _db.Entry(customerFromDb).State = EntityState.Modified; _db.SaveChanges(); return("Success"); } return("Error"); }
public string RegisterDealer(Dealer dealer) { try { //Check if dealer already exists var dealerFromDb = _db.Dealer.Where(u => u.Email == dealer.Email).FirstOrDefault(); if (dealerFromDb == null) { dealer.CreatedDate = DateTime.Now; dealer.UpdatedDate = DateTime.Now; dealer.IsActive = true; _db.Dealer.Add(dealer); _db.SaveChanges(); return("Success"); } return("Dealer already exists"); } catch (Exception e) { throw; } }
public string RegisterMechanic(Mechanic Mechanic) { try { //Check if Mechanic already exists var MechanicFromDb = _db.Mechanic.Where(u => u.Email == Mechanic.Email).FirstOrDefault(); if (MechanicFromDb == null) { Mechanic.CreatedDate = DateTime.Now; Mechanic.UpdatedDate = DateTime.Now; Mechanic.IsActive = true; _db.Mechanic.Add(Mechanic); _db.SaveChanges(); return("Success"); } return("Mechanic already exists"); } catch (Exception e) { throw; } }
public string RegisterVehicle(Vehicle Vehicle) { try { //Check if Vehicle already exists var VehicleFromDb = _db.Vehicle.Where(u => u.LicensePlate == Vehicle.LicensePlate).FirstOrDefault(); if (VehicleFromDb == null) { Vehicle.CreatedDate = DateTime.Now; Vehicle.UpdatedDate = DateTime.Now; Vehicle.IsActive = true; _db.Vehicle.Add(Vehicle); _db.SaveChanges(); return("Success"); } return("Vehicle already exists"); } catch (Exception e) { throw; } }
public string AcceptAppointment(int id) { var appointmentFromDb = _db.Appointment.Where(c => c.Id == id).FirstOrDefault(); if (appointmentFromDb != null) { appointmentFromDb.Status = "Accepted"; _db.Entry(appointmentFromDb).State = EntityState.Modified; _db.SaveChanges(); return("Success"); } return("Invalid Appointment"); }
public string Register(Customer newCustomer) { try { //Check if user already exists var userFromDb = _db.Customer.Where(u => u.Email == newCustomer.Email).FirstOrDefault(); if (userFromDb == null) { var salt = AuthenticationHelper.GenerateSalt(10); var password = AuthenticationHelper.EncodePassword(newCustomer.Password, salt); newCustomer.Salt = salt; newCustomer.Password = password; newCustomer.CreatedDate = DateTime.Now; newCustomer.UpdatedDate = DateTime.Now; newCustomer.IsActive = true; _db.Customer.Add(newCustomer); _db.SaveChanges(); return("Success"); } return("User already exists"); } catch (Exception e) { throw; } }
public string RegisterService(Service Service) { try { //Check if Service already exists var ServiceFromDb = _db.Service.Where(u => u.Name == Service.Name).FirstOrDefault(); if (ServiceFromDb == null) { Service.IsActive = true; _db.Service.Add(Service); _db.SaveChanges(); return("Success"); } return("Service already exists"); } catch (Exception e) { throw; } }