예제 #1
0
        public async Task <IActionResult> Put(int id, [FromForm] AssignmentDtoForEdit assignment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _response = await _repo.EditAssignment(id, assignment);

            return(Ok(_response));
        }
예제 #2
0
        public async Task <ServiceResponse <object> > EditAssignment(int id, AssignmentDtoForEdit assignment)
        {
            ClassSectionAssignment dbObj = _context.ClassSectionAssignment.FirstOrDefault(s => s.Id.Equals(id));

            if (dbObj != null)
            {
                DateTime DueDateTime    = DateTime.ParseExact(assignment.DueDateTime, "MM/dd/yyyy", null);
                var      UserObj        = _context.Users.Where(m => m.Id == _LoggedIn_UserID).FirstOrDefault();
                var      SubjectObj     = _context.Subjects.Where(m => m.Id == assignment.SubjectId).FirstOrDefault();
                var      AssignmentName = $"{DateTime.UtcNow.ToShortDateString()} - {UserObj?.FullName} - {SubjectObj?.Name}";
                dbObj.AssignmentName = AssignmentName;
                dbObj.Details        = assignment.Details;
                dbObj.ClassSectionId = assignment.ClassSectionId;
                dbObj.ReferenceUrl   = assignment.ReferenceUrl;
                dbObj.IsPosted       = assignment.IsPosted;
                dbObj.DueDateTime    = DueDateTime;
                dbObj.SubjectId      = assignment.SubjectId;

                if (assignment.files != null && assignment.files.Count() > 0)
                {
                    for (int i = 0; i < assignment.files.Count(); i++)
                    {
                        var dbPath = _filesRepository.SaveFile(assignment.files[i]);
                        if (string.IsNullOrEmpty(dbObj.RelatedMaterial))
                        {
                            dbObj.RelatedMaterial = dbObj.RelatedMaterial + dbPath;
                        }
                        else
                        {
                            dbObj.RelatedMaterial = dbObj.RelatedMaterial + "||" + dbPath;
                        }
                        if (string.IsNullOrEmpty(dbObj.FileName))
                        {
                            dbObj.FileName = dbObj.FileName + assignment.files[i].FileName + ",," + dbPath;
                        }
                        else
                        {
                            dbObj.FileName = dbObj.FileName + "||" + assignment.files[i].FileName + ",," + dbPath;
                        }
                    }
                }
                _context.ClassSectionAssignment.Update(dbObj);
                await _context.SaveChangesAsync();
            }
            _serviceResponse.Success = true;
            _serviceResponse.Message = CustomMessage.Updated;
            return(_serviceResponse);
        }