public IHttpActionResult Post(CompanyCarCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var category = _categoryRepository.GetById(model.Category);

            if (category == null)
            {
                return(BadRequest("Invalid Category"));
            }

            var CompanyCar = new CompanyCar();

            CompanyCar.Name       = model.Name;
            CompanyCar.CategoryId = model.Category;

            var result = _companyCarRepository.Add(CompanyCar);

            if (result == null)
            {
                return(BadRequest());
            }


            return(Ok(result));
        }
Exemple #2
0
        public async Task <ActionResult <CompanyCar> > PostCompanyCar(CompanyCar companyCar)
        {
            _context.CompanyCar.Add(companyCar);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCompanyCar", new { id = companyCar.CompanyCarID }, companyCar));
        }
Exemple #3
0
        public async Task <IActionResult> PutCompanyCar(int id, CompanyCar companyCar)
        {
            if (id != companyCar.CompanyCarID)
            {
                return(BadRequest());
            }

            _context.Entry(companyCar).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyCarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #4
0
        private async Task OnLode()
        {
            Employee = HttpContext.Session.GetLogin(_context.Employee);

            CompanyCarList = await _context.CompanyCar
                             .Include(c => c.Company).Where(e => e.Company_CompanyID == Employee.Company_CompanyID).ToListAsync();

            select         = new CompanyCar();
            select         = CompanyCarList.FirstOrDefault(e => e.Status.Equals("Open"));
            CompanyCarList = CompanyCarList.Where(e => e.Status.Equals("Close")).ToList();
        }
Exemple #5
0
 public CompanyCar Update(CompanyCar entity)
 {
     try
     {
         return(repository.Update(entity));
     }
     catch (Exception ex)
     {
         logger.Error("Namespace:CompanyCarRepository || \t Method: Update ||\t Ex.Msg : " + ex.Message);
         return(null);
     }
 }
Exemple #6
0
 public bool Remove(CompanyCar entity)
 {
     try
     {
         repository.Remove(entity);
         return(true);
     }
     catch (Exception ex)
     {
         logger.Error("Namespace:CompanyCarRepository || \t Method: Remove ||\t Ex.Msg : " + ex.Message);
         return(false);
     }
 }
Exemple #7
0
        public CompanyCar Add(CompanyCar entity)
        {
            var response = new Response();

            try
            {
                return(repository.Add(entity));
            }
            catch (Exception ex)
            {
                logger.Error("Namespace:CompanyCarRepository || \t Method: Add ||\t Ex.Msg : " + ex.Message);
                return(null);
            }
        }
Exemple #8
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            Employee = HttpContext.Session.GetLogin(_context.Employee);
            if (id == null)
            {
                return(NotFound());
            }

            CompanyCar = await _context.CompanyCar
                         .Include(c => c.Company).FirstOrDefaultAsync(m => m.CompanyCarID == id);

            if (CompanyCar == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            Employee = HttpContext.Session.GetLogin(_context.Employee);
            if (id == null)
            {
                return(NotFound());
            }

            CompanyCar = await _context.CompanyCar
                         .Include(c => c.Company).FirstOrDefaultAsync(m => m.CompanyCarID == id);

            if (CompanyCar == null)
            {
                return(NotFound());
            }
            ViewData["Company_CompanyID"] = new SelectList(_context.Company, "CompanyID", "Image");
            return(Page());
        }
Exemple #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Employee = HttpContext.Session.GetLogin(_context.Employee);
            if (id == null)
            {
                return(NotFound());
            }

            CompanyCar = await _context.CompanyCar.FindAsync(id);

            if (CompanyCar != null)
            {
                _context.CompanyCar.Remove(CompanyCar);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #11
0
        public void DeleteCompanyCarTest()
        {
            var carCategory = new Category()
            {
                Id = 1, Name = "Car"
            };
            var toyota = new CompanyCar()
            {
                Id = 1, Name = "Toyota", Category = carCategory, CategoryId = 1
            };

            var mockRepo = new Mock <ICompanyCarRepository>();

            mockRepo.Setup(a => a.GetById(It.IsAny <int>())).Returns(toyota);
            mockRepo.Setup(a => a.Remove(It.IsAny <int>())).Returns(true);
            var companyCarController = new CompanyCarController(mockRepo.Object, _categoryRepository);

            var result = companyCarController.Delete(1) as OkNegotiatedContentResult <CompanyCar>;

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(1, result.Content.Id);
        }
Exemple #12
0
        public async Task <IActionResult> OnGetAsync()
        {
            OT = await _context.OT.Where(e => e.TypStatus.Equals("Close")).ToListAsync();

            OTa = await _context.OT.Where(e => e.TypStatus.Equals("Open") || e.TypStatus.Equals("Manage Car")).ToListAsync();

            try
            {
                Employee = HttpContext.Session.GetLogin(_context.Employee);
            }
            catch (Exception)
            {
                return(RedirectToPage("./index"));
            }
            if (Employee == null)
            {
                return(NotFound());
            }
            var CompanyCarList = await _context.CompanyCar.Where(e => e.Company_CompanyID == Employee.Company_CompanyID).ToListAsync();

            CompanyCar = CompanyCarList.FirstOrDefault(e => e.Status.Equals("Open"));
            return(Page());
        }