コード例 #1
0
 public Models.UpdateResult SaveLabel(Models.Label label)
 {
     return(Execute(cx =>
     {
         try
         {
             cx.Database.ExecuteSqlCommand("SetLabel @p0, @p1, @p2",
                                           new SqlParameter {
                 ParameterName = "p0", Value = label.Language
             },
                                           new SqlParameter {
                 ParameterName = "p1", Value = label.LabelName
             },
                                           new SqlParameter {
                 ParameterName = "p2", Value = label.Value
             }
                                           );
             return new Models.UpdateResult(true);
         }
         catch (Exception ex)
         {
             return new Models.UpdateResult("Error updating label: {0}", ex.Message);
         }
     }));
 }
コード例 #2
0
        public void PutAsync_Failed_LabelExisted()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            var labelModel = new Models.Label {
                Id = 1, Name = "LabelA"
            };

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult(labelModel));
            var labels = new List <Models.Label>()
            {
                labelModel, new Models.Label {
                    Name = "LabelB"
                }
            };

            mockLabelRepo.Setup(x => x.GetLabelsAsync()).Returns(Task.FromResult(labels.AsEnumerable()));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 3, Name = "LabelA"
            };
            var response = controller.PutAsync(3, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label '{label.Name}' already exists, cannot update.");
        }
コード例 #3
0
        public async Task <ActionResult <Models.DTO.LabelDTO> > Post(Models.DTO.LabelDTO label)
        {
            if (label.Name == null)
            {
                return(BadRequest($"Label name not provided"));
            }

            if (_dbContext.Labels
                .AsEnumerable()
                .Any(l => string.Equals(l.Name, label.Name, StringComparison.CurrentCultureIgnoreCase)))
            {
                return(Conflict($"Label '{label.Name}' already exists."));
            }

            Models.Label newLabel = new Models.Label(label);
            newLabel.LabelId = 0;

            _dbContext.Labels.Add(newLabel);
            await _dbContext.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(Get),
                       new { id = newLabel.LabelId },
                       new Models.DTO.LabelDTO(newLabel)
                       ));
        }
コード例 #4
0
        public void PutAsync_Failed_LabelIsNullOrWhiteSpace(string labelName)
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mockMapper    = new Mock <IMapper>();

            var labelModel = new Models.Label {
                Id = 1, Name = "LabelA"
            };

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult(labelModel));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mockMapper.Object, mockLabelRepo.Object);

            // Act
            var label = new DTOs.Label {
                Id = 1, Name = labelName
            };
            var response = controller.PutAsync(1, label);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(400);
            result.Value.ShouldBe($"Label could be neither null nor whitespace.");
        }
コード例 #5
0
        private void _adapter_OnLabelSelected(object sender, Models.Label e)
        {
            Intent returnIntent = new Intent();

            returnIntent.PutExtra("selectedLabel", e.Name);
            SetResult(Result.Ok, returnIntent);
            Finish();
        }
コード例 #6
0
        public async Task <InvokeResult> UpdateLabelAsync(Models.Label label, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(label, AuthorizeResult.AuthorizeActions.Update, user, org);

            var result = Validator.Validate(label, Actions.Update);
            await _repo.UpdateLabelAsync(label);

            return(result.ToInvokeResult());
        }
コード例 #7
0
        public async Task <InvokeResult> AddLabelAsync(Models.Label label, EntityHeader org, EntityHeader user)
        {
            ValidationCheck(label, Actions.Create);
            await AuthorizeAsync(label, AuthorizeResult.AuthorizeActions.Create, user, org);

            await _repo.AddLabelAsync(label);

            return(InvokeResult.Success);
        }
コード例 #8
0
ファイル: Mapper.cs プロジェクト: messier16/MyIssues
        public static MyIssues.Models.Label Map(this Octokit.Label label)
        {
            var colors = label.Color.GetInts();
            var l      = new Models.Label
            {
                Name = label.Name,
                R    = colors[0],
                G    = colors[1],
                B    = colors[2]
            };

            return(l);
        }
コード例 #9
0
        public ActionResult <Models.DTO.LabelDTO> Get(int id)
        {
            Models.Label label =
                _dbContext.Labels
                .AsTracking()
                .FirstOrDefault(l => l.LabelId == id);

            if (label == null)
            {
                return(NotFound());
            }

            return(new Models.DTO.LabelDTO(label));
        }
コード例 #10
0
        public void PutAsync_Succeed()
        {
            var mockLabelRepo = new Mock <ILabelRepository>();
            var mockLogger    = new Mock <ILogger <LabelsController> >();
            var mapper        = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(new Mappings.MappingProfile())));

            var labelModel = new Models.Label {
                Id = 1, Name = "LabelA"
            };

            mockLabelRepo.Setup(x => x.GetLabelAsync(It.IsAny <int>())).Returns(Task.FromResult(labelModel));
            var labels = new List <Models.Label>()
            {
                labelModel, new Models.Label {
                    Name = "LabelB"
                }
            };

            mockLabelRepo.Setup(x => x.GetLabelsAsync()).Returns(Task.FromResult(labels.AsEnumerable()));
            var newLabelModel = new Models.Label {
                Id = 1, Name = "NewLabel"
            };

            mockLabelRepo.Setup(x => x.UpdateLabelAsync(It.IsAny <Models.Label>())).Returns(Task.FromResult(newLabelModel));

            // Arrange
            var controller = new LabelsController(mockLogger.Object, mapper, mockLabelRepo.Object);

            // Act
            var labelDTO = new DTOs.Label {
                Id = 1, Name = "NewLabel"
            };
            var response = controller.PutAsync(1, labelDTO);

            // Assert
            var result = response.Result.Result as ObjectResult;

            result.StatusCode.ShouldBe(200);
            var returnedLabel = result.Value as DTOs.Label;

            returnedLabel.Name.ShouldBe(labelDTO.Name);
        }
コード例 #11
0
ファイル: LabelController.cs プロジェクト: Esbj/SFF
        public async Task <ActionResult <Models.Label> > CreateLabel(int RentalId)
        {
            var rental = await _context.Rentals.FindAsync(RentalId);

            var movie = await(from Movie in _context.Movies
                              where rental.MovieId == Movie.Id
                              select Movie).ToListAsync();

            var assosiation = await(from Assos in _context.Assosiations
                                    where rental.AssosiationId == Assos.Id
                                    select Assos).ToListAsync();

            var adress = assosiation.FirstOrDefault();
            var title  = movie.FirstOrDefault();

            Models.Label label = new Models.Label();

            label.Adress = adress.Location;
            label.Title  = title.Title;
            label.Date   = rental.Date;

            return(label);
        }
コード例 #12
0
 public LabelJson(Models.Label label)
 {
     id          = label.Id;
     name        = label.Name;
     description = label.Description;
 }
コード例 #13
0
 public async Task <Models.Label> Update([FromBody] Models.Label labelToUpdate, string id, string Token)
 {
     return(await _labelService.Update(id, labelToUpdate, Token));
 }
コード例 #14
0
 public void Bind(Models.Label item, EventHandler <Models.Label> listener)
 {
     _boundItem  = item;
     _boundEvent = listener;
 }