Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] string CustomerCard)
        {
            List <CustomerCardRowAddDto> customerCardRowAddDtos = JsonConvert.DeserializeObject <List <CustomerCardRowAddDto> >(CustomerCard);
            CustomerCardAddDto           customerCardAddDto     = new CustomerCardAddDto();

            customerCardAddDto.CustomerCardRowAddDto = customerCardRowAddDtos;
            User user = await _userManager.FindById(Convert.ToInt32(customerCardRowAddDtos[0].ProductManagerName));

            customerCardAddDto.CustomerCardName   = customerCardRowAddDtos[0].CustomerCardName;
            customerCardAddDto.ProductManagerName = user.Name;
            Customer customer = _customerManager.Find(x => x.CustomerId == Convert.ToInt32(customerCardRowAddDtos[0].CustomerName));

            customerCardAddDto.CustomerName = customer.CustomerName;
            customerCardAddDto.FinishedDate = DateTime.Now.AddDays(7);
            if (ModelState.IsValid)
            {
                List <CustomerCardRow> customerCardRow = _mapper.Map <List <CustomerCardRow> >(customerCardRowAddDtos);
                CustomerCard           customerCardAdd = _mapper.Map <CustomerCard>(customerCardAddDto);
                customerCardRow.ForEach(x => x.CustomerCardId = customerCardAdd.CustomerCardId);
                customerCardAdd.CustomerCardRow = customerCardRow;
                customerCardAdd.CustomerId      = customer.CustomerId;
                customerCardAdd.CostOfCardTime  = customerCardAdd.CustomerCardRow.Count * 4;
                await _customerCardManager.AddAsync(customerCardAdd);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(CustomerCard));
            }
        }
        public async Task <IActionResult> Index(int id)
        {
            CustomerCard customerCard = await _customerCardManager.FindById(id);

            Customer customer = await _customerManager.FindById(id);

            List <CustomerCardRow> customerCardRows = await _customerCardRowManager.GetAllASync(x => x.CustomerCardId == id);

            List <CustomerCardRowAddDto> customerCardRowAddDto = _mapper.Map <List <CustomerCardRowAddDto> >(customerCardRows);

            CustomerCardAddDto customerCardAddDto = _mapper.Map <CustomerCardAddDto>(customerCard);

            customerCardAddDto.CustomerCardRowAddDto = customerCardRowAddDto;
            customerCardAddDto.CreateDate            = customerCard.CreatedDate;
            return(View(customerCardAddDto));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id)
        {
            CustomerCard customerCard = await _customerCardManager.FindById(id);

            List <CustomerCardRow> customerCardRows = await _customerCardRowManager.GetAllASync(x => x.CustomerCardId == id);


            List <CustomerCardRowAddDto> customerCardRowAddDto = _mapper.Map <List <CustomerCardRowAddDto> >(customerCardRows);

            CustomerCardAddDto customerCardAddDto = _mapper.Map <CustomerCardAddDto>(customerCard);
            List <User>        users = await _userManager.GetAllASync();

            var user = users.Find(x => x.Name == customerCard.ProductManagerName);

            customerCardAddDto.CustomerCardRowAddDto = customerCardRowAddDto;
            ViewBag.CustomerId              = new SelectList(await _customerManager.GetAllASync(x => x.CustomerId == customerCard.CustomerId), "CustomerId", "CustomerName");
            ViewBag.DeveloperName           = new SelectList(users, "UserId", "Name");
            ViewBag.ProductId               = new SelectList(users, "UserId", "Name", user.UserId);
            customerCardAddDto.FinishedDate = DateTime.Now;
            return(View(customerCardAddDto));
        }