/// <summary>
        /// Inserts a new row into customers table
        /// </summary>
        /// <param name="customer">New customer that has to be inserted</param>
        /// <returns>Same customer after inserting</returns>
        public CustomerViewModel InsertCustomer(InsertCustomerViewModel customerViewModel)
        {
            if (customerViewModel.DateOfJoining > Convert.ToDateTime("2000-01-01"))
            {
                //convert ViewModel (InsertCustomerViewModel) to DomainModel (Customer)
                Customer customer = new Customer();
                customer.CustomerName  = customerViewModel.CustomerName;
                customer.DateOfJoining = customerViewModel.DateOfJoining;
                //initialize the customer id
                customer.CustomerID = Guid.NewGuid();

                //convert Customer to CustomerViewModel
                Customer          customerAfterInsert          = customersDataAccess.InsertCustomer(customer);
                CustomerViewModel customerViewModelAfterInsert = new CustomerViewModel()
                {
                    CustomerID   = customerAfterInsert.CustomerID,
                    CustomerName = customerAfterInsert.CustomerName
                };

                return(customerViewModelAfterInsert);
            }
            else
            {
                //return null;
                throw new Exception("Date of joining should be greater than Jan 01 1950");
            }
        }
예제 #2
0
        public string InsertCustomer(InsertCustomerViewModel data)
        {
            string result = string.Empty;

            if (!this._CustomersRepository.Insert(data))
            {
                result = "新增失敗";
            }
            return(result);
        }
예제 #3
0
        public ActionResult Insert(InsertCustomerViewModel data)
        {
            var isInsert = this._CustomerLogic.InsertCustomer(data);

            if (string.IsNullOrWhiteSpace(isInsert))
            {
                return(RedirectToAction("Index", "Customer"));
            }

            TempData["message"] = isInsert;
            return(View());
        }
예제 #4
0
 public void Insert(InsertCustomerViewModel dto, out bool Status)
 {
     try
     {
         var model = new Customer
         {
             CustomerName     = dto.CustomerName,
             CustomerLocation = dto.CustomerLocation
         };
         _uow.Customers.Add(model);
         _uow.SaveChanges();
         Status = true;
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        public bool Insert(InsertCustomerViewModel data)
        {
            bool   result = true;
            string sql    = string.Empty;

            sql = @"INSERT INTO Customers
                   (firstname
                   ,lastname
                   ,age
                   ,birthday
                   ,email
                   ,createdate
                   ,updatedate)
                    VALUES
                    (@firstname, @lastname, @age, @birthday, @email, GETDATE(), null)";

            DynamicParameters param = new DynamicParameters();

            param.Add("firstname", data.firstname);
            param.Add("lastname", data.lastname);
            param.Add("age", data.age);
            param.Add("birthday", data.birthday);
            param.Add("email", data.email);

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString.DemoDB))
                {
                    conn.Execute(sql, param);
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
        public async Task <IActionResult> InsertAsync(InsertCustomerViewModel dto)
        {
            var Status = false;
            var Result = new Res();

            BackgroundJob.Enqueue(() => _customerServices.Insert(dto, out Status));
            await Task.Run(() => _customerServices.Insert(dto, out Status));

            if (Status)
            {
                Result.Status     = true;
                Result.Message    = MesssageContant.SAVE_SUCCESS;
                Result.StatusCode = HttpStatusCode.OK;
            }
            else
            {
                Result.Data       = null;
                Result.Status     = Status;
                Result.Message    = MesssageContant.SAVE_FAIL;
                Result.StatusCode = HttpStatusCode.InternalServerError;
            }
            return(Ok(Result));
        }
 public CustomerViewModel InsertCustomer(InsertCustomerViewModel customer)
 {
     return(new CustomerViewModel());
 }
        //POST: /api/Customers
        public CustomerViewModel Post(InsertCustomerViewModel customerViewModel)
        {
            CustomerViewModel customerAfterInsert = customersBusinessLogic.InsertCustomer(customerViewModel);

            return(customerAfterInsert);
        }