Exemplo n.º 1
0
 internal static Types.Classification.Put.ClassificationUpdateData UpdateData(Types.Classification.Post.ClassificationCreateData createData)
 {
     return(new Types.Classification.Put.ClassificationUpdateData()
     {
         Action = createData.Action
     });
 }
Exemplo n.º 2
0
 internal static Core.Classification Core(Types.Classification.Post.ClassificationCreateData data)
 {
     return(new Core.Classification()
     {
         UserID = data.Who.ID,
         SkelbimasID = data.What.ID,
         Action = CoreAction(data.Action)
     });
 }
        public async Task <ActionResult <Types.Classification.Classification> > PostSkelbimasClassification(Types.Classification.Post.ClassificationCreateData data)
        {
            if (!_context.Users.Any(item => item.ID == data.Who.ID))
            {
                return(BadRequest("User doesn't exist."));
            }
            if (!_context.Skelbimai.Any(item => item.ID == data.What.ID))
            {
                await new SkelbimasController(_context)
                .PostSkelbimas(data.What)
                ;
                //return BadRequest("Skelbimas doesn't exist.");
            }
            var x = await _context.Classifications.FirstOrDefaultAsync(item => item.SkelbimasID == data.What.ID && item.UserID == data.Who.ID);

            if (x != null)
            {
                return(await PutSkelbimasClassification(x.ID, Helpers.Classification.UpdateData(data)));

                //return BadRequest("Assignment from this User to this Skelbimas already exist.");
                //return await PutSkelbimasClassification(, );
            }

            var skelbimasClassification = Helpers.Classification.Core(data);

            _context.Classifications.Add(skelbimasClassification);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetClassifications", new { userID = skelbimasClassification.UserID, skelbimasID = skelbimasClassification.SkelbimasID },
                                   new Helpers.Classification.ClassificationDeep(null, skelbimasClassification)
                                   ));
        }