Example #1
0
        public async Task <object> Add(LabInputModel labInputModel)
        {
            var groupModel = await _context.Group.FindAsync(labInputModel.GroupId);

            if ((await getLabIdByName(labInputModel.Name) > 0) || groupModel == null)
            {
                return("bad request");
            }
            var model = new LabModel
            {
                GroupId     = labInputModel.GroupId,
                Name        = labInputModel.Name,
                DateTime    = labInputModel.DateTime,
                Title       = labInputModel.Title,
                Description = labInputModel.Description,
                Curricula   = labInputModel.Curricula,
            };

            _context.Lab.Add(model);
            try
            {
                await _context.SaveChangesAsync();
            } catch (Exception)
            {
                return("bad request");
            }
            return(model);
        }
Example #2
0
        public async Task <IActionResult> PutLabModel(LabInputModel labModel)
        {
            var result = await _labRepository.Update(labModel);

            if (result.Equals("no content"))
            {
                return(NoContent());
            }
            else if (result.Equals("not found"))
            {
                return(NotFound());
            }
            else
            {
                return(BadRequest());
            }
        }
Example #3
0
        public async Task <object> PostLabModel(LabInputModel labModel)
        {
            object result;

            if (await _labRepository.GetByName(labModel.Name) == null)
            {
                result = await _labRepository.Add(labModel);
            }
            else
            {
                result = "bad request";
            }

            if (result.Equals("bad request"))
            {
                return(BadRequest());
            }
            else
            {
                return(result);
            }
        }
Example #4
0
        public async Task <string> Update(LabInputModel labInputModel)
        {
            if (await getLabIdByName(labInputModel.Name) != labInputModel.LabId)
            {
                return("bad request");
            }

            var model = await _context.Lab.FindAsync(labInputModel.LabId);

            if (model == null)
            {
                return("bad request");
            }
            model.Name                  = labInputModel.Name;
            model.DateTime              = labInputModel.DateTime;
            model.Title                 = labInputModel.Title;
            model.Curricula             = labInputModel.Curricula;
            model.Description           = labInputModel.Description;
            _context.Entry(model).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LabModelExists(model.LabId))
                {
                    return("not found");
                }
                else
                {
                    throw;
                }
            }

            return("no content");
        }