Ejemplo n.º 1
0
        public async Task <ApiResponse <BarberDTO> > ChangeBarberStatus(CheckBarber checkBarber)
        {
            ApiResponse <BarberDTO> result = new ApiResponse <BarberDTO>();

            try
            {
                Barber barberToEdit = await unitOfWork.BarbersManager.GetByIdAsync(checkBarber.Id);

                if (barberToEdit != null)
                {
                    var            info            = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");
                    DateTimeOffset localServerTime = DateTimeOffset.Now;
                    DateTimeOffset localTime       = TimeZoneInfo.ConvertTime(localServerTime, info);

                    DateTime date = localTime.DateTime;
                    var      barberLoginsResult = await unitOfWork.BarberLoginsManager.GetAsync(result => result.BarberId == checkBarber.Id && result.LoginDateTime.Value.Date == checkBarber.Date.Value.Date);

                    BarberLogin login = barberLoginsResult.FirstOrDefault();



                    if (login != null)
                    {
                        if (login.logoutDateTime == null)
                        {
                            if (barberToEdit.Status == "Available")
                            {
                                barberToEdit.Status = "Unavailable";
                            }
                            else
                            {
                                barberToEdit.Status = "Available";
                            }

                            var res = await unitOfWork.BarbersManager.UpdateAsync(barberToEdit);

                            await unitOfWork.SaveChangesAsync();

                            if (res == true)
                            {
                                result.Succeeded = true;
                                result.Data      = mapper.Map <BarberDTO>(barberToEdit);
                                return(result);
                            }
                            else
                            {
                                result.Succeeded = false;
                                result.Errors.Add("Failed to update barber status !");
                                return(result);
                            }
                        }
                        else
                        {
                            result.Succeeded = false;
                            result.Errors.Add("A barber is already Sign Out !");
                            return(result);
                        }
                    }


                    else
                    {
                        result.Succeeded = false;
                        result.Errors.Add("barber is not logged in !");
                        return(result);
                    }
                }
                else
                {
                    result.Succeeded = false;
                    result.Errors.Add("Failed to find specified barber !");
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.Succeeded = false;
                result.Errors.Add(ex.Message);
                return(result);
            }
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> ChangeBarberStatus(CheckBarber checkBarber)
 {
     return(await EditItemResponseHandler(async() => await service.ChangeBarberStatus(checkBarber)));
 }