Ejemplo n.º 1
0
        public async Task <IActionResult> PutWorkshop_ApplicationBulkStatus(
            [FromQuery] string apikey,
            [FromBody] ChangeWAStatusBulk newstati,
            [FromHeader(Name = "jwttoken")] string jwttoken,
            [FromHeader(Name = "conference_id")] int conference_id)
        {
            if (this.auth.KeyIsValid(apikey) && this.jwtService.PermissionLevelValid(jwttoken, "admin"))
            {
                var count = 0;
                foreach (UserToWS utw in newstati.UsersToWorkshop)
                {
                    var thisWA = this._context.Workshop_Application.Where(wa => wa.ApplicantUID == utw.UID && wa.WorkshopID == utw.WorkshopID).FirstOrDefault();
                    if (thisWA == null)
                    {
                        thisWA = new Workshop_Application
                        {
                            ApplicantUID = utw.UID,
                            WorkshopID   = utw.WorkshopID,
                            Priority     = 1,
                            Status       = this.StatusToString(WAStatus.IsAttendee),
                        };
                        this._context.Workshop_Application.Add(thisWA);
                    }
                    else
                    {
                        thisWA.Status = this.StatusToString(newstati.NewStatus);
                        this._context.Entry(thisWA).State = EntityState.Modified;
                    }


                    try
                    {
                        await this._context.SaveChangesAsync();

                        count += 1;
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!this.Workshop_ApplicationExists(thisWA.WorkshopID, thisWA.ApplicantUID))
                        {
                            this.telBot.SendTextMessage($"WA for {thisWA.ApplicantUID} and {thisWA.WorkshopID} not in Database");
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                this.telBot.SendTextMessage($"Successfully changed Status of {count} Workshop Applications to {newstati.NewStatus}");
                return(this.Ok());
            }

            return(this.Unauthorized());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutWorkshop_Application(
            [FromBody] Workshop_Application workshop_Application,
            [FromHeader] string jwttoken,
            [FromQuery] string apikey)
        {
            // Permission Level Admin
            // TODO add History
            if (this.jwtService.PermissionLevelValid(jwttoken, "admin") && this.auth.KeyIsValid(apikey))
            {
                if (!this.ModelState.IsValid)
                {
                    return(this.BadRequest(this.ModelState));
                }

                this._context.Entry(workshop_Application).State = EntityState.Modified;

                try
                {
                    await this._context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.Workshop_ApplicationExists(workshop_Application.WorkshopID, workshop_Application.ApplicantUID))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.NoContent());
            }

            return(this.Unauthorized());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostWorkshop_Application(
            [FromBody] List <BulkApplication> applications,
            [FromHeader] string jwttoken,
            [FromQuery] string apikey)
        {
            // Permission Level User
            if (this.jwtService.PermissionLevelValid(jwttoken, "user") && this.auth.KeyIsValid(apikey))
            {
                var uid = string.Empty;
                if (!this.ModelState.IsValid)
                {
                    return(this.BadRequest(this.ModelState));
                }

                foreach (BulkApplication application in applications)
                {
                    User user = this._context.User.Where(u => u.UID == application.Applicant_UID).FirstOrDefault();
                    uid = user.UID;
                    Workshop workshop = this._context.Workshop.Where(ws => ws.WorkshopID == application.Workshop_ID).FirstOrDefault();
                    if (workshop == null || user == null)
                    {
                        return(this.NotFound());
                    }

                    Workshop_Application wa = new Workshop_Application
                    {
                        User         = user,
                        ApplicantUID = application.Applicant_UID,
                        WorkshopID   = application.Workshop_ID,
                        Workshop     = workshop,
                        Priority     = application.Priority,
                        Status       = "HasApplied",
                    };
                    this._context.Workshop_Application.Add(wa);
                }

                try
                {
                    await this._context.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    /*if (this.Workshop_ApplicationExists(workshop_Application.WorkshopID, workshop_Application.ApplicantUID))
                     * {
                     *  return new StatusCodeResult(StatusCodes.Status409Conflict);
                     * }
                     * else
                     * {
                     *  throw;
                     * }*/
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }

                this.telBot.SendTextMessage($"New Workshop Application from {uid}");
                return(this.Ok());

                // return this.CreatedAtAction("GetWorkshop_Application", new { id = workshop_Application.WorkshopID }, workshop_Application);
            }

            return(this.Unauthorized());
        }