Esempio n. 1
0
        public JsonResult AddEventsTypes(PortalEventTypes portalEventTypes)
        {
            try
            {
                var token = _tokenValidator.Validate(HttpContext);
                if (!token.Success)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = $"Unauthorized:-{token.Message}",
                    }));
                }

                if (token.Role != Role.Admin)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = "Sorry, you are not authorized to perform this action",
                    }));
                }

                if (!string.IsNullOrEmpty(portalEventTypes.EventTypeName))
                {
                    var eventsType = new PortalEventTypes
                    {
                        EventTypeName = portalEventTypes.EventTypeName
                    };

                    _context.PortalEventTypes.Add(eventsType);
                    _context.SaveChanges();

                    return(Json(new ReturnData <string>
                    {
                        Success = true,
                        Message = "Event type added successfully"
                    }));
                }

                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "Event type name can not be empty"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "An error occurred,please retry : " + ex.Message
                }));
            }
        }
Esempio n. 2
0
        public JsonResult EditEventsType(PortalEventTypes portalEventTypes)
        {
            try
            {
                var token = _tokenValidator.Validate(HttpContext);
                if (!token.Success)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = $"Unauthorized:-{token.Message}",
                    }));
                }

                if (token.Role != Role.Admin)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        NotAuthenticated = true,
                        Message = "Sorry, you are not authorized to access this page",
                    }));
                }

                var eventTypes = _context.PortalEventTypes.FirstOrDefault(t => t.Id == portalEventTypes.Id);
                if (eventTypes == null)
                {
                    return(Json(new ReturnData <string>
                    {
                        Success = false,
                        Message = "Could not find event type"
                    }));
                }

                eventTypes.EventTypeName = portalEventTypes.EventTypeName;

                _context.Update(eventTypes);
                _context.SaveChanges();

                return(Json(new ReturnData <string>
                {
                    Success = true,
                    Message = "Event updated successfully"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ReturnData <string>
                {
                    Success = false,
                    Message = "Server Error, Please try again",
                    Error = new Error(ex)
                }));
            }
        }