Exemplo n.º 1
0
        public void MassCreateComputerUsingHistories()
        {
            var random = new Random();

            var listAppUser = AppUserManager.Users;
            var firstUser   = listAppUser.First();

            var fakeComputerUsingHistories = new List <ComputerUsingHistoryViewModel>();

            for (int i = 0; i < 10; i++)
            {
                var computerUsingHistory = new ComputerUsingHistoryViewModel()
                {
                    ComputerId = random.Next(1, 5),
                    UserId     = firstUser.Id,
                    Status     = true,
                    StartTime  = DateTime.Now,
                    EndTime    = DateTime.Now.AddHours(random.Next(2, 4))
                };
                fakeComputerUsingHistories.Add(computerUsingHistory);
            }

            foreach (var computerUsingHistoryViewModel in fakeComputerUsingHistories)
            {
                var newComputerUsingHistory = new ComputerUsingHistory();
                newComputerUsingHistory.UpdateComputerUsingHistory(computerUsingHistoryViewModel);

                _computerUsingHistoryService.Add(newComputerUsingHistory);
                _computerUsingHistoryService.Save();
            }
        }
        public HttpResponseMessage Put(HttpRequestMessage request, ComputerUsingHistoryViewModel computerTypeVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.Values.FirstOrDefault()?.Errors.FirstOrDefault()?.ErrorMessage);
                }
                else
                {
                    var computerTypeDb = _computerUsingHistoryService.GetById(computerTypeVm.ComputerUsingHistoryId);
                    computerTypeDb.UpdateComputerUsingHistory(computerTypeVm);
                    _computerUsingHistoryService.Update(computerTypeDb);
                    _computerUsingHistoryService.Save();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                return response;
            }));
        }
        public HttpResponseMessage Post(HttpRequestMessage request, ComputerUsingHistoryViewModel computerTypeVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.Values.FirstOrDefault()?.Errors.FirstOrDefault()?.ErrorMessage);
                }
                else
                {
                    var newComputerUsingHistory = new ComputerUsingHistory();
                    newComputerUsingHistory.UpdateComputerUsingHistory(computerTypeVm);

                    var computerUsingHistory = _computerUsingHistoryService.Add(newComputerUsingHistory);
                    _computerUsingHistoryService.Save();

                    response = request.CreateResponse(HttpStatusCode.Created, computerUsingHistory);
                }
                return response;
            }));
        }
Exemplo n.º 4
0
        public static void UpdateComputerUsingHistory(this ComputerUsingHistory computerUsingHistory, ComputerUsingHistoryViewModel computerUsingHistoryVm)
        {
            computerUsingHistory.ComputerUsingHistoryId = computerUsingHistoryVm.ComputerUsingHistoryId;
            computerUsingHistory.ComputerId             = computerUsingHistoryVm.ComputerId;
            computerUsingHistory.UserId    = computerUsingHistoryVm.UserId;
            computerUsingHistory.StartTime = computerUsingHistoryVm.StartTime;
            computerUsingHistory.EndTime   = computerUsingHistoryVm.EndTime;
            computerUsingHistory.StartTime = computerUsingHistoryVm.StartTime;
            computerUsingHistory.EndTime   = computerUsingHistoryVm.EndTime;

            computerUsingHistory.CreatedDate     = computerUsingHistoryVm.CreatedDate;
            computerUsingHistory.CreatedBy       = computerUsingHistoryVm.CreatedBy;
            computerUsingHistory.UpdatedDate     = computerUsingHistoryVm.UpdatedDate;
            computerUsingHistory.UpdatedBy       = computerUsingHistoryVm.UpdatedBy;
            computerUsingHistory.MetaKeyword     = computerUsingHistoryVm.MetaKeyword;
            computerUsingHistory.MetaDescription = computerUsingHistoryVm.MetaDescription;
            computerUsingHistory.Status          = computerUsingHistoryVm.Status;
        }