コード例 #1
0
        public IActionResult PatchAppointmentHour(int customworkdayId, int id, [FromBody] JsonPatchDocument <CustomAppointmentHourForUpdateData> patchDoc)
        {
            var    claimsPrincipal = User as ClaimsPrincipal;
            string role            = claimsPrincipal.FindFirst("role").Value;
            int    barberId        = int.Parse(claimsPrincipal.FindFirst("userId").Value);

            if (!role.Equals("client"))
            {
                CustomAppointmentHour customAppointmentHour = role.Equals("admin") ? CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id) :
                                                              CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId && wd.BarberId == barberId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id);
                if (customAppointmentHour == null)
                {
                    return(NotFound());
                }
                CustomAppointmentHourForUpdateData patchData = new CustomAppointmentHourForUpdateData()
                {
                    Hour    = customAppointmentHour.Hour,
                    Visible = customAppointmentHour.Visible
                };

                patchDoc.ApplyTo(patchData);
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                customAppointmentHour.Hour    = patchData.Hour;
                customAppointmentHour.Visible = patchData.Visible;
                return(NoContent());
            }
            return(Unauthorized());
        }
コード例 #2
0
        public IActionResult CreateCustomAppointmentHour(int customworkdayId, [FromBody] CustomAppointmentHourForCreateData data)
        {
            ClaimsPrincipal claimsPrincipal = User as ClaimsPrincipal;
            string          role            = claimsPrincipal.FindFirst("role").Value;
            int             barberId        = int.Parse(claimsPrincipal.FindFirst("userId").Value);

            if (!role.Equals("client"))
            {
                CustomWorkDay customWorkday = role.Equals("admin") ? CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId) :
                                              CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId && wd.BarberId == barberId);
                if (customWorkday == null)
                {
                    return(NotFound());
                }
                int maxCustomAppointmentHourId = CustomWorkDaysDataStore.Current.Days.SelectMany(wd => wd.CustomAppointmentHour).Max(ah => ah.Id);

                CustomAppointmentHour newCustomAppointmentHour = new CustomAppointmentHour()
                {
                    Id      = ++maxCustomAppointmentHourId,
                    Visible = data.Visible,
                    Hour    = data.Hour
                };
                customWorkday.CustomAppointmentHour.Add(newCustomAppointmentHour);
                return(CreatedAtRoute(role.Equals("admin") ? "GetCustomAppointmentHourById" : "GetCustomAppointmentHourByIdForBarber", new { customworkdayId, id = newCustomAppointmentHour.Id }, newCustomAppointmentHour));
            }
            return(Unauthorized());
        }
コード例 #3
0
        public IActionResult GetCustomAppointmentHourById(int customworkdayId, int id)
        {
            CustomAppointmentHour customAppointmentHour = CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id);

            if (customAppointmentHour == null)
            {
                return(NotFound());
            }
            return(Ok(customAppointmentHour));
        }
コード例 #4
0
        public IActionResult GetCustomAppointmentHourByIdForBarber(int customworkdayId, int id)
        {
            ClaimsPrincipal       claimsPrincipal       = User as ClaimsPrincipal;
            int                   barberId              = int.Parse(claimsPrincipal.FindFirst("userId").Value);
            CustomAppointmentHour customAppointmentHour = CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId && wd.BarberId == barberId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id);

            if (customAppointmentHour == null)
            {
                return(NotFound());
            }
            return(Ok(customAppointmentHour));
        }
コード例 #5
0
        public IActionResult DeleteAppointmentHourById(int customworkdayId, int id)
        {
            ClaimsPrincipal claimsPrincipal = User as ClaimsPrincipal;
            string          role            = claimsPrincipal.FindFirst("role").Value;
            int             barberId        = int.Parse(claimsPrincipal.FindFirst("userId").Value);

            if (!role.Equals("client"))
            {
                CustomAppointmentHour customAppointmentHour = role.Equals("admin") ? CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id) :
                                                              CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId && wd.BarberId == barberId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id);
                if (customAppointmentHour == null)
                {
                    return(NotFound());
                }
                CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId).CustomAppointmentHour.Remove(customAppointmentHour);
                return(NoContent());
            }
            return(Unauthorized());
        }
コード例 #6
0
        public IActionResult UpdateAppointmentHour(int customworkdayId, int id, [FromBody] CustomAppointmentHourForUpdateData data)
        {
            var    claimsPrincipal = User as ClaimsPrincipal;
            string role            = claimsPrincipal.FindFirst("role").Value;
            int    barberId        = int.Parse(claimsPrincipal.FindFirst("userId").Value);

            if (!role.Equals("client"))
            {
                CustomAppointmentHour customAppointmentHour = role.Equals("admin") ? CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id) :
                                                              CustomWorkDaysDataStore.Current.Days.FirstOrDefault(wd => wd.Id == customworkdayId && wd.BarberId == barberId).CustomAppointmentHour.FirstOrDefault(ah => ah.Id == id);
                if (customAppointmentHour == null)
                {
                    return(NotFound());
                }
                customAppointmentHour.Hour    = data.Hour;
                customAppointmentHour.Visible = data.Visible;
                return(NoContent());
            }
            return(Unauthorized());
        }