public async Task Put(HomePageMessage mess)
        {
            mess.Posted = DateTime.Now.ToUniversalTime();

            _db.Entry(mess).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _db.SaveChangesAsync();
        }
        public IHttpActionResult UpdateNote(int id, Note note)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            if (id != note.Id)
            {
                var errorString = string.Format($"{id} not {note.Id}");
                return(BadRequest(errorString));
            }

            db.Entry(note).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task Put(Sequencer seq)
        {
            Sequencer modified = await _db.Sequencer.SingleAsync(p => p.UserId == seq.UserId && p.NoteFileId == seq.NoteFileId);

            modified.LastTime         = DateTime.Now.ToUniversalTime();
            _db.Entry(modified).State = EntityState.Modified;
            await _db.SaveChangesAsync();
        }
        public async Task <IActionResult> EditContent(NoteContent nc)
        {
            NoteContent edited = await _context.NoteContent.SingleAsync(p => p.NoteHeaderId == nc.NoteHeaderId);

            edited.NoteBody        = nc.NoteBody;
            edited.DirectorMessage = nc.DirectorMessage;

            await AccessManager.Audit(_context, "EditContent", User.Identity.Name,
                                      User.Identity.Name, "Edit Content NoteID " + edited.NoteHeaderId);

            _context.Entry(edited).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", new { id = await NoteDataManager.GetNoteById(_context, nc.NoteHeaderId) }));
        }
        public UpdateState Update(NoteViewModel note)
        {
            using (var context = new NotesDbContext()){
                Note original = context.Notes
                                .Include(it => it.NoteCategories)
                                .ThenInclude(noteCategory => noteCategory.Category)
                                .FirstOrDefault(dbNote => dbNote.NoteID == note.Id);

                if (original == null)
                {
                    return(UpdateState.Deleted);
                }

                context.Entry(original).Property("RowVersion").OriginalValue = note.RowVersion;
                original.Title          = note.Title;
                original.NoteDate       = note.Date;
                original.Description    = note.Content;
                original.NoteCategories = mapStringCategoriesToNoteCategory(context, note.Categories, original);

                try{
                    context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException e) {
                    var exceptionEntry = e.Entries.Single();
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();

                    if (databaseEntry == null)
                    {
                        return(UpdateState.Deleted);
                    }
                    return(UpdateState.Changed);
                }

                return(UpdateState.Ok);
            }
        }
        public async Task <IActionResult> Create(SQLFile sQLFile, IFormFile file)
        {
            long retId = 0;

            string fname = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim('"');

            string nameonly = Path.GetFileNameWithoutExtension(fname);
            string extonly  = Path.GetExtension(fname);


            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
#pragma warning disable 162
            if (true || ModelState.IsValid)
#pragma warning restore 162
            {
                try
                {
                    if (file.Length > 0 && file.Length < 0x7FFFFFFF)
                    {
                        if (!file.ContentType.StartsWith("image") && !User.IsInRole("Admin"))
                        {
                            return(RedirectToAction("Index"));
                        }

                        SQLFileContent content = new SQLFileContent {
                            Content = new byte[file.Length]
                        };
                        using (Stream reader = file.OpenReadStream())
                        {
                            int x = await reader.ReadAsync(content.Content, 0, (int)file.Length);

                            if (x != file.Length)
                            {
                                return(RedirectToAction("Index"));
                            }
                        }

                        sQLFile.ContentType = file.ContentType;
                        sQLFile.Contributor = User.Identity.Name;
                        sQLFile.FileName    = fname;

                        _sqlcontext.SQLFile.Add(sQLFile);
                        await _sqlcontext.SaveChangesAsync();

                        retId = sQLFile.FileId;

                        content.SQLFileId = retId;
                        _sqlcontext.SQLFileContent.Add(content);
                        await _sqlcontext.SaveChangesAsync();

                        retId = content.SQLFileId;

                        fname            = nameonly + "." + retId + extonly;
                        sQLFile.FileName = fname;
                        _sqlcontext.Entry(sQLFile).State = EntityState.Modified;
                        await _sqlcontext.SaveChangesAsync();
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception)
                {
                    //string meg = ex.Message;
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }

                if (retId < 1)
                {
                    return(RedirectToAction("Index"));
                }



                return(RedirectToAction("Index"));
            }

            // ReSharper disable once HeuristicUnreachableCode
#pragma warning disable 162
            return(RedirectToAction("Index"));

#pragma warning restore 162
        }
Beispiel #7
0
 public async Task Put(UserData uData)
 {
     _db.Entry(uData).State = EntityState.Modified;
     int count = await _db.SaveChangesAsync();
 }
 public async ValueTask <int> UpdateAsync(UploadFile uploadFile)
 {
     _notesDbContext.Entry(uploadFile).Property(e => e.Version).OriginalValue = uploadFile.Version;
     _notesDbContext.UploadFiles.Update(uploadFile);
     return(await _notesDbContext.SaveChangesAsync());
 }
Beispiel #9
0
 public async Task Put(LinkedFile linkedFile)
 {
     _db.Entry(linkedFile).State = EntityState.Modified;
     await _db.SaveChangesAsync();
 }
Beispiel #10
0
        public async Task Save(IList <IFormFile> UploadFiles)
        {
            try
            {
                foreach (IFormFile file in UploadFiles)
                {
                    var filename = ContentDispositionHeaderValue
                                   .Parse(file.ContentDisposition)
                                   .FileName
                                   .Trim('"');

                    string nameonly = Path.GetFileNameWithoutExtension(filename);
                    string extonly  = Path.GetExtension(filename);
                    string fname    = nameonly + extonly;

                    SQLFile x = await _db.SQLFile.SingleOrDefaultAsync(p => p.FileName == fname);

                    if (x != null) // already exists
                    {
                        Response.Clear();
                        Response.StatusCode = 409;
                        Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = "File already exists";
                        return;
                    }

                    SQLFile        SqlFile        = new SQLFile();
                    SQLFileContent SqlFileContent = new SQLFileContent {
                        Content = new byte[file.Length]
                    };
                    using (Stream reader = file.OpenReadStream())
                    {
                        int xx = await reader.ReadAsync(SqlFileContent.Content, 0, (int)file.Length);

                        if (xx != file.Length)
                        {
                            Response.Clear();
                            Response.StatusCode = 204;
                            Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
                            return;
                        }
                    }

                    SqlFile.ContentType = file.ContentType;
                    SqlFile.Contributor = "unknown";
                    SqlFile.FileName    = filename;

                    _db.SQLFile.Add(SqlFile);
                    await _db.SaveChangesAsync();

                    long retId = SqlFile.FileId;

                    SqlFileContent.SQLFileId = retId;
                    _db.SQLFileContent.Add(SqlFileContent);
                    await _db.SaveChangesAsync();

                    retId = SqlFileContent.SQLFileId;

                    SqlFile.FileName         = fname;
                    _db.Entry(SqlFile).State = EntityState.Modified;
                    await _db.SaveChangesAsync();


                    //filename = hostingEnv.ContentRootPath + "\\wwwroot" + $@"\{filename}";
                    //if (!System.IO.File.Exists(filename))
                    //{
                    //    using (FileStream fs = System.IO.File.Create(filename))
                    //    {
                    //        file.CopyTo(fs);
                    //        fs.Flush();
                    //    }
                    //}
                }
            }
            catch (Exception e)
            {
                Response.Clear();
                Response.StatusCode = 204;
                Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
                Response.HttpContext.Features.Get <IHttpResponseFeature>().ReasonPhrase = e.Message;
            }
        }