示例#1
0
        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
            });
        }
示例#2
0
        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
            });
        }
示例#3
0
 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);
 }
示例#4
0
        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);
        }
示例#5
0
        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);
        }