public async Task <ApiResponse <bool> > SignOutBarberAdmin(BarberLogoutRequestAdminDTO request)
        {
            ApiResponse <bool> result = new ApiResponse <bool>();

            try
            {
                Barber barber = await unitOfWork.BarbersManager.GetByIdAsync(request.BarberId);

                if (barber != null)
                {
                    var barberLoginResult = await unitOfWork.BarberLoginsManager.GetAsync(b => b.BarberId == request.BarberId && b.LoginDateTime.Value.Date == request.Time.Date);

                    if (barberLoginResult.FirstOrDefault() == null)
                    {
                        result.Succeeded = false;
                        result.Data      = false;
                        result.Errors.Add("Barber hasn't signed in today , Barber needs to sign in first in order to be able to sign out !");
                        return(result);
                    }
                    else
                    {
                        BarberLogin    barberLoginToEdit = barberLoginResult.FirstOrDefault();
                        var            info            = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");
                        DateTimeOffset localServerTime = DateTimeOffset.Now;
                        DateTimeOffset localTime       = TimeZoneInfo.ConvertTime(localServerTime, info);
                        request.Time = localTime.DateTime;
                        barberLoginToEdit.logoutDateTime = request.Time;

                        barber.Status = "Unavailable";

                        var res = await unitOfWork.BarberLoginsManager.UpdateAsync(barberLoginToEdit);

                        await unitOfWork.SaveChangesAsync();

                        if (res == true)
                        {
                            result.Succeeded = true;
                            result.Data      = true;
                            return(result);
                        }
                        else
                        {
                            result.Succeeded = false;
                            result.Data      = false;
                            result.Errors.Add("Failed to sign out barber !");
                            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);
            }
        }
Esempio n. 2
0
 public async Task <IActionResult> SignOutBarber(BarberLogoutRequestAdminDTO request)
 {
     return(await EditItemResponseHandler(async() => await service.SignOutBarberAdmin(request)));
 }