コード例 #1
0
        public async Task <IActionResult> Delete(CustomerListDto customerListDto)
        {
            Customer deletedCustomer = _mapper.Map <Customer>(customerListDto);
            await _customerManager.DeleteCustomer(deletedCustomer.CustomerId);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> Delete(int id)
        {
            Customer deletedCustomer = await _customerManager.FindById(id);

            CustomerListDto customer = _mapper.Map <CustomerListDto>(deletedCustomer);

            return(View(customer));
        }
コード例 #3
0
        public async Task <IActionResult> GetAllCustomersForOrganization(bool active)
        {
            var customers  = new List <Customer>();
            var UsersOrgId = int.Parse(User.FindFirst("Organization").Value);

            if (active)
            {
                customers = await _context.Customers.Where(x => x.OrganizationId == UsersOrgId && x.CustomerStatus != Status.Inactive).ToListAsync();
            }
            else
            {
                customers = await _context.Customers.Where(x => x.OrganizationId == UsersOrgId && x.CustomerStatus == Status.Inactive).ToListAsync();
            }

            var customerList = new List <CustomerListDto>();

            foreach (var customer in customers)
            {
                var responsiblecontactperson = "";

                if (await _context.Contactpersons.AnyAsync(x => x.CustomerId == customer.Id && x.Responsible == true))
                {
                    responsiblecontactperson = (await _context.Contactpersons.SingleOrDefaultAsync(x => x.CustomerId == customer.Id && x.Responsible == true)).Name;
                }

                else
                {
                    responsiblecontactperson = "None";
                }

                var customerDto = new CustomerListDto()
                {
                    Id                 = customer.Id,
                    Name               = customer.Name,
                    Region             = customer.Region,
                    OrganizationNumber = customer.OrganizationNumber,
                    Responsible        = responsiblecontactperson,
                    Status             = customer.CustomerStatus.ToString()
                };
                customerList.Add(customerDto);
            }

            return(Ok(customerList));
        }
コード例 #4
0
        public async Task <int> UpdateCustomerAsync(CustomerListDto dto)
        {
            var sql = " UPDATE [dbo].[Project] " +
                      " SET [CustName] = @CustName " +
                      "  ,[CustShortName] = @CustShortName " +
                      "  ,[CustEngName] = @CustEngName " +
                      "  ,[CustContactName] = @CustContactName " +
                      "  ,[CustContactEmail] = @CustContactEmail " +
                      "  ,[CustContactPhone] = @CustContactPhone " +
                      "  ,[CustContactFax] = @CustContactFax " +
                      "  ,[CustContactSkype] = @CustContactSkype " +
                      "  ,[CustAddress] = @CustAddress " +
                      "  ,[CustWebsite] = @CustWebsite " +
                      "  ,[CustPostCode] = @CustPostCode " +
                      "  ,[CustComment] = @CustComment " +
                      "  ,[CustStyleCss] = @CustStyleCss " +
                      "  ,[UpdatedId] = @UpdatedId" +
                      "  ,[UpdatedDate] = GetDate() " +
                      " WHERE  Id = @Id";

            var x = await Connection.ExecuteAsync(sql, new
            {
                CustName         = dto.CustName,
                CustShortName    = dto.CustShortName,
                CustEngName      = dto.CustEngName,
                CustContactName  = dto.CustContactName,
                CustContactEmail = dto.CustContactEmail,
                CustContactPhone = dto.CustContactPhone,
                CustContactFax   = dto.CustContactFax,
                CustContactSkype = dto.CustContactSkype,
                CustAddress      = dto.CustAddress,
                CustWebsite      = dto.CustWebsite,
                CustPostCode     = dto.CustPostCode,
                CustComment      = dto.CustComment,
                CustStyleCss     = dto.CustStyleCss,
                UpdatedId        = dto.UpdatedId,
            }, Transaction);

            return(x);
        }
コード例 #5
0
        public async Task <IActionResult> Post([FromBody] CustomerListDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = "Not a valid model" + ModelState.ToString() }));
            }
            try
            {
                _UnitOfWork.Transaction = _UnitOfWork.Begin();

                var id = await _UnitOfWork.CustomerRepository.InsertCustomerAsync(dto);

                _UnitOfWork.Commit();

                return(Ok(id));
            }
            catch (Exception ex)
            {
                _UnitOfWork.Dispose();
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #6
0
        public ActionResult <CustomerListDto> GetAll(int page = 1, int size = 10)
        {
            try
            {
                var    customers = _service.GetAllCustomers(page, size);
                int    total     = _service.TotalCustomers;
                string next      = string.Empty;

                if (page * size < total)
                {
                    next = Url.Action(nameof(GetAll), new { page = page + 1, size = size });
                }

                var data     = _mapper.Map <IEnumerable <Customer>, IEnumerable <CustomerDto> >(customers);
                var response = new CustomerListDto {
                    Data = data, Next = next, Total = total
                };
                return(Ok(response));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(BadRequest());
            }
        }
コード例 #7
0
 public void ShowCustomerDetails(CustomerListDto dto)
 {
     _eventAggregator.Publish(new ShowCustomerDetailsEvent(dto.Id));
 }
コード例 #8
0
        public async Task <int> InsertCustomerAsync(CustomerListDto dto)
        {
            var sql = " DECLARE @ID int;" +
                      " INSERT INTO [dbo].[Customer] " +
                      " ([CustName] " +
                      " ,[CustShortName] " +
                      " ,[CustEngName] " +
                      " ,[CustContactName] " +
                      " ,[CustContactEmail] " +
                      " ,[CustContactPhone] " +
                      " ,[CustContactFax] " +
                      " ,[CustContactSkype] " +
                      " ,[CustAddress] " +
                      " ,[CustWebsite] " +
                      " ,[CustPostCode] " +
                      " ,[CustComment] " +
                      " ,[CustIsDelete] " +
                      " ,[CreatedId] " +
                      " ,[CreatedDate] " +
                      " ,[CustStyleCss]) " +
                      " VALUES " +
                      " (@CustName " +
                      " ,@CustShortName" +
                      " ,@CustEngName " +
                      " ,@CustContactName " +
                      " ,@CustContactEmail " +
                      " ,@CustContactPhone " +
                      " ,@CustContactFax " +
                      " ,@CustContactSkype " +
                      " ,@CustAddress " +
                      " ,@CustWebsite " +
                      " ,@CustPostCode " +
                      " , @CustComment " +
                      " ,@CustIsDelete " +
                      " ,@CreatedId " +
                      " ,GETDATE()" +
                      " ,@CustStyleCss)" +
                      " SET @ID = SCOPE_IDENTITY(); " +
                      " SELECT @ID";

            var id = await Connection.QuerySingleAsync <int>(sql, new
            {
                CustName         = dto.CustName,
                CustShortName    = dto.CustShortName,
                CustEngName      = dto.CustEngName,
                CustContactName  = dto.CustContactName,
                CustContactEmail = dto.CustContactEmail,
                CustContactPhone = dto.CustContactPhone,
                CustContactFax   = dto.CustContactFax,
                CustContactSkype = dto.CustContactSkype,
                CustAddress      = dto.CustAddress,
                CustWebsite      = dto.CustWebsite,
                CustPostCode     = dto.CustPostCode,
                CustComment      = dto.CustComment,
                CustIsDelete     = 0,
                CreatedId        = dto.CreatedId,
                CustStyleCss     = dto.CustStyleCss,
            }, Transaction);

            return(id);
        }