コード例 #1
0
 public ResursaValoareFlat(ResursaValoare rv)
 {
     this.Id              = rv.IdresursaDict;
     this.Nume            = rv.IdresursaDictNavigation.Nume;
     this.Valoare         = rv.IdresursaDictNavigation.Valoare;
     this.TableValue      = rv.IdresursaDictNavigation.TableValue;
     this.ValoareData     = rv.Valoare;
     this.UniqueId        = rv.UniqueId;
     this.DataIntroducere = rv.Unique.DataIntroducere;
 }
コード例 #2
0
        public async Task <IActionResult> PostResursaValoare([FromServices] CatalogROContext context, string id, [FromBody] ResursaValoareFlat[] resursaValoares)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ids = resursaValoares.Select(it => it.Id).ToArray();
            var rds = await context.ResursaDict.Where(rd => ids.Contains(rd.Id)).ToArrayAsync();

            if (rds.Length != ids.Length)
            {
                throw new ArgumentException($"NOT same number of arguments {rds.Length} {ids.Length}");
            }
            var names = rds.Select(it => it.Nume).Distinct().ToArray();

            if (names?.Length != 1)
            {
                throw new ArgumentException($"multiple names");
            }
            if (names[0] != id)
            {
                throw new ArgumentException($"not correct name");
            }
            var ri = new ResursaInregistrare();

            ri.Identuziast     = 1;
            ri.UniqueId        = Guid.NewGuid();
            ri.DataIntroducere = DateTime.UtcNow;
            context.ResursaInregistrare.Add(ri);
            await context.SaveChangesAsync();

            foreach (var rv in resursaValoares)
            {
                var rvNew = new ResursaValoare();
                rvNew.IdresursaDict = rv.Id;
                rvNew.UniqueId      = ri.UniqueId;
                rvNew.Valoare       = rv.ValoareData;
                context.Add(rvNew);
            }
            await context.SaveChangesAsync();

            return(CreatedAtAction("GetResursaValoare", new { id = ri.UniqueId }));
        }