Exemplo n.º 1
0
        public bool Insert(string name, string nameArea)
        {
            try
            {
                AreaService areaService = new AreaService(_context);
                Area        area        = areaService.GetArea(nameArea);
                if (area == null)
                {
                    return(false);
                }

                Tables tables = new Tables
                {
                    nameTable = name,
                    status    = false,
                    Note      = null
                };

                tables.Area = area;
                _context.Tables.Add(tables);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool updateTables(object tables)
        {
            try
            {
                DataTable dataTable = new DataTable();
                dataTable.Clear();
                dataTable.Columns.Add("Id", typeof(string));
                dataTable.Columns.Add("nameTable", typeof(string));
                dataTable.Columns.Add("status", typeof(bool));
                dataTable.Columns.Add("Note", typeof(string));
                dataTable.Columns.Add("nameArea", typeof(string));

                AreaService areaService = new AreaService(_context);
                dataTable = tables as DataTable;
                int i = 0;
                foreach (DataRow item in dataTable.Rows)
                {
                    Guid   IdTable   = new Guid(item.Table.Rows[i]["Id"].ToString());
                    string nameTable = item.Table.Rows[i]["nameTable"].ToString();
                    bool   status    = (bool)(item.Table.Rows[i]["status"]);
                    string Note      = item.Table.Rows[i]["Note"].ToString();
                    string nameArea  = item.Table.Rows[i]["nameArea"].ToString();

                    Area area = areaService.GetArea(nameArea);
                    if (area != null)
                    {
                        var table = _context.Tables.Where(x => x.Id == IdTable).Include(x => x.Area).SingleOrDefault();
                        table.nameTable = nameTable;
                        table.status    = status;
                        table.Note      = Note;
                        table.Area      = area;
                        _context.SaveChanges();
                    }
                    i++;
                }
                return(true);
            }
            catch (Exception)
            {
            }
            return(false);
        }