public ActionResult AddBarberServiceForTest( [FromQuery] string barberId, [FromQuery] string name, [FromQuery] int durationMinute) { BarberServices service = new BarberServices { BarberId = barberId, Name = name, DurationMinute = durationMinute, InUsed = true, CreatedTime = DateTimeUtil.GetTimeNow() }; var rs = _barberService.AddOrUpdateBarberService(service); if (rs != null) { return(new JsonResult(new { service = rs }) { StatusCode = StatusCodes.Status200OK }); } return(new JsonResult("Cannot create service") { StatusCode = StatusCodes.Status409Conflict }); }
public ActionResult AddBarberService([FromBody] BarberServiceViewModel serviceViewModel) { BarberServices service = new BarberServices { Id = serviceViewModel.Id, BarberId = serviceViewModel.BarberId, Name = serviceViewModel.Name, DurationMinute = serviceViewModel.DurationMinute, Price = serviceViewModel.Price, Currency = serviceViewModel.Currency, InUsed = true, CreatedTime = DateTimeUtil.GetTimeNow() }; var rs = _barberService.AddOrUpdateBarberService(service); if (rs != null) { return(new JsonResult(new { service = rs }) { StatusCode = StatusCodes.Status200OK }); } return(new JsonResult("Cannot create or update service") { StatusCode = StatusCodes.Status500InternalServerError }); }
public static bool EqualsTo(this BarberServices service1, BarberServices service2) { return(service1.InUsed && service2.InUsed && service1.Name == service2.Name && service1.DurationMinute == service2.DurationMinute && service1.Price == service2.Price && service1.Currency == service2.Currency); }
public bool RemoveBarberService(int serviceId) { BarberServices service = _serviceRepository.GetById(serviceId); if (service != null) { service.InUsed = false; service.ExpiredTime = DateTimeUtil.GetTimeNow(); _serviceRepository.Update(service); return(true); } return(false); }
public BarberServices AddOrUpdateBarberService(BarberServices service) { BarberServices currentService = _serviceRepository.GetById(service.Id); if (currentService != null) { if (currentService.EqualsTo(service)) { //When nothing changed return(currentService); } RemoveBarberService(service.Id); } service.Id = default(int); var rs = _serviceRepository.Add(service); return(rs); }