Esempio n. 1
0
        public IActionResult EditTask(int projectId, int id, TaskDto taskDto)
        {
            var updatedTask = (DbMetadata.Models.Task)taskDto;

            updatedTask.ProjectId             = projectId;
            updatedTask.TaskId                = id;
            _context.Entry(updatedTask).State = EntityState.Modified;
            _context.SaveChanges();

            return(Ok(new
            {
                action = "updated"
            }));
        }
        public void UpdateTheme(Theme theme, string[] metadataRelated)
        {
            _dbContext.Database.ExecuteSqlCommand("DELETE FROM ThemeMetadatas WHERE Theme_Id = {0}", theme.Id);
            _dbContext.Database.ExecuteSqlCommand("DELETE FROM ThemeMetadataSortings WHERE Theme_Id = {0}", theme.Id);

            if (metadataRelated != null)
            {
                int sorting = 1;

                foreach (var uuid in metadataRelated)
                {
                    var metadata = _dbContext.Metadatas.Where(m => m.Uuid == uuid).FirstOrDefault();

                    if (metadata == null)
                    {
                        _dbContext.Metadatas.Add(new Metadata {
                            Uuid = uuid
                        });
                        _dbContext.SaveChanges();
                    }

                    _dbContext.Database.ExecuteSqlCommand("INSERT INTO ThemeMetadatas(Theme_Id, Metadata_Uuid) VALUES({0}, {1})", theme.Id, uuid);
                    _dbContext.Database.ExecuteSqlCommand("INSERT INTO ThemeMetadataSortings(Theme_Id, Metadata_Uuid, Sorting) VALUES({0}, {1}, {2})", theme.Id, uuid, sorting);
                    sorting++;
                }
            }

            _dbContext.Database.ExecuteSqlCommand("DELETE FROM ThemeTranslations WHERE ThemeId = {0}", theme.Id);
            foreach (var translation in theme.Translations.ToList())
            {
                _dbContext.Database.ExecuteSqlCommand("INSERT INTO ThemeTranslations(ThemeId,Name,Description,CultureName, Id) VALUES({0}, {1}, {2}, {3}, {4})",
                                                      translation.ThemeId, translation.Name, translation.Description, translation.CultureName, Guid.NewGuid());
            }

            _dbContext.Entry(theme).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }