Esempio n. 1
0
        // With a single object (model and entity) get the object for update and save changes (async flavor)
        protected async virtual Task <TReturn> UpdateOneAsync <TReturn>(TIdentifier identifier, Func <EntityModelPair <TEntity, TModel>, Task <TReturn> > updateAsync)
        {
            var response = await WithOneAsync(identifier, updateAsync, tracking : true);

            await Database.SaveChangesAsync();

            await CacheInvalidate(identifier);

            return(response);
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,CreationDate,Name,FamilyName,E_Mail,UserID,Visible")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(profile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(profile));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("ID,CreationDate,Name,ShortName")] Association association)
        {
            if (ModelState.IsValid)
            {
                _context.Add(association);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(association));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ID,Title,CreationDate,ValidFromDate,ValidTillDate,Text,Visible,BelongsToAssocID")] Document document)
        {
            if (ModelState.IsValid)
            {
                _context.Add(document);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(document));
        }
        public async Task <IActionResult> Create(List <IFormFile> file, [FromForm] string titulo, [FromForm] string processo, [FromForm] string categoria, Documents documents)
        {
            if (ModelState.IsValid)
            {
                this.convertFileByte(file, titulo, processo, categoria, documents);

                _context.Add(documents);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(documents));
        }
Esempio n. 6
0
        public async Task <User> Update(int id, User user)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Users.FirstOrDefaultAsync(u => u.Id == id);

                    if (entity != null)
                    {
                        user.Password = Encryption.Encrypt(user.Password);
                        context.Entry(entity).CurrentValues.SetValues(user);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => user));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 7
0
        public async Task <Category> Insert(Category category)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var categoryInserted = context.Categories.Add(category);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => categoryInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 8
0
        public async Task <Galery> Insert(Galery galery)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var galeryInserted = context.Galeries.Add(galery);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => galeryInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 9
0
        public async Task <Document> Insert(Document document)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var documentInserted = context.Documents.Add(document);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => documentInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public async Task <User> Insert(User user)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    user.Password = Encryption.Encrypt(user.Password);
                    var userInserted = context.Users.Add(user);
                    await context.SaveChangesAsync();

                    return(await Task.Run(() => userInserted));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 11
0
        public async Task Delete(int id)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Categories.FirstOrDefaultAsync(c => c.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).State = EntityState.Deleted;
                        await context.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 12
0
        public async Task <Category> Update(int id, Category category)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Categories.FirstOrDefaultAsync(a => a.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).CurrentValues.SetValues(category);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => category));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 13
0
        public async Task <Document> Update(int id, Document document)
        {
            try
            {
                using (var context = new DocumentsContext())
                {
                    var entity = await context.Documents.FirstOrDefaultAsync(d => d.Id == id);

                    if (entity != null)
                    {
                        context.Entry(entity).CurrentValues.SetValues(document);
                        await context.SaveChangesAsync();

                        return(await Task.Run(() => document));
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }