Ejemplo n.º 1
0
        public async Task CreateOrUpdate(Fidget fidget, string userName, bool canApproveFidgets)
        {
            var existing = await _context.Fidgets.FindAsync(fidget.Id);

            if (existing == null)
            {
                await _context.Fidgets.AddAsync(fidget);
            }
            else
            {
                var findType = await _context.FidgetTypes.FindAsync(fidget.TypeId);

                existing.Color = fidget.Color;
                existing.Name  = fidget.Name;
                if (canApproveFidgets && !existing.IsApproved && fidget.IsApproved)
                {
                    existing.IsApproved = fidget.IsApproved;
                    existing.ApprovedBy = userName;
                }

                existing.Type = findType; // better, but i don't like this
            }

            await _context.SaveChangesAsync(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateOrUpdateFidget(Fidget fidget)
        {
            if (User == null)
            {
                return(Unauthorized());
            }
            await _fidgetRepository.CreateOrUpdate(fidget, AuthenticatedUserName, CanApproveFidgets);

            return(Ok());
        }